Archived
0

Переход на Gradle

This commit is contained in:
2017-03-06 21:46:55 +03:00
parent 8d54ef0cd0
commit 5c34dbc17f
11 changed files with 140 additions and 115 deletions

4
.gitignore vendored
View File

@@ -15,10 +15,14 @@ bin/
## GRADLE ## ## GRADLE ##
.gradle/ .gradle/
build/ build/
gradle/
gradlew
gradlew.bat
## MAVEN ## ## MAVEN ##
target/ target/
## OTHER ## ## OTHER ##
lib/ lib/
felix-cache/

20
build.gradle Normal file
View File

@@ -0,0 +1,20 @@
subprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
ext {
slf4jVersion = '1.7.21'
}
dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
}
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}

23
core/build.gradle Normal file
View File

@@ -0,0 +1,23 @@
group = 'asys'
version = '0.0-SNAPSHOT'
apply plugin: 'application'
mainClassName = "asys.core.Main"
jar {
manifest {
attributes 'Implementation-Title': 'ASys Core',
'Implementation-Version': version,
'Main-Class': mainClassName
}
baseName = project.group + '.' + project.name
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
dependencies {
runtime group: 'org.slf4j', name: 'slf4j-simple', version: slf4jVersion
compile group: 'org.apache.felix', name: 'org.apache.felix.framework', version: '5.6.1'
compile group: 'com.google.guava', name: 'guava', version: '21.0'
}

View File

@@ -13,10 +13,7 @@ import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.apache.felix.framework.util.FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP; import static org.apache.felix.framework.util.FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP;
@@ -24,14 +21,19 @@ public class Core {
private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Logger logger = LoggerFactory.getLogger(this.getClass());
private Felix felix; private Felix felix;
private BundleActivator hostActivator; private BundleActivator hostActivator;
private Properties properties;
public Core() { public Core() {
logger.trace("core created"); logger.trace("core created");
} }
public void setProperties(Properties properties) {
this.properties = properties;
}
@PostConstruct @PostConstruct
public void start() { public void start() {
hostActivator = new HostActivator(); hostActivator = new HostActivator(properties.getProperty("asys.bundles.dir"));
startFelix(); startFelix();
} }
@@ -53,6 +55,7 @@ public class Core {
config.put("felix.fileinstall.poll", 250); config.put("felix.fileinstall.poll", 250);
config.put("felix.fileinstall.log.level", 2); config.put("felix.fileinstall.log.level", 2);
config.put("felix.fileinstall.noInitialDelay", true); config.put("felix.fileinstall.noInitialDelay", true);
config.put("org.osgi.framework.system.packages.extra", "com.sun.net.httpserver");
return ImmutableMap.newInstance(config); return ImmutableMap.newInstance(config);
} }

View File

@@ -0,0 +1,59 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2017-03-02
*/
package asys.core;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class HostActivator implements BundleActivator {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Path BUNDLES_DIR;
public HostActivator(String bundlesDir) {
this.BUNDLES_DIR = Paths.get(bundlesDir);
}
@Override
public void start(BundleContext bundleContext) throws Exception {
logger.trace("call [HostActivator.start(BundleContext)]");
List<Bundle> bundleList = new ArrayList<>();
Files.list(BUNDLES_DIR).forEach(path -> {
try {
InputStream inputStream = Files.newInputStream(path);
if (inputStream != null) {
bundleList.add(bundleContext.installBundle(path.toUri().toString(), inputStream));
}
} catch (IOException | BundleException e) {
e.printStackTrace();
}
});
for (Bundle bundle : bundleList) {
logger.trace("{} | {} | State: {}", bundle.getBundleId(),
bundle.getSymbolicName(), bundle.getState());
if (bundle.getState() == Bundle.INSTALLED) {
logger.trace("\tStarted");
}
}
}
@Override
public void stop(BundleContext bundleContext) throws Exception {
logger.trace("call [HostActivator.stop(BundleContext)]");
}
}

View File

@@ -0,0 +1,23 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2017-03-02
*/
package asys.core;
import java.io.IOException;
import java.util.Properties;
public class Main {
public static void main(String[] args) {
Properties asysProperties = new Properties();
try {
asysProperties.load(Main.class.getResourceAsStream("/asys.properties"));
} catch (IOException e) {
throw new RuntimeException(e);
}
Core asysCore = new Core();
asysCore.setProperties(asysProperties);
asysCore.start();
}
}

View File

@@ -0,0 +1 @@
asys.bundles.dir = modules

74
pom.xml
View File

@@ -1,74 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>ASys Core</name>
<groupId>asys</groupId>
<artifactId>asys-core</artifactId>
<packaging>jar</packaging>
<version>0.0-SNAPSHOT</version>
<developers>
<developer>
<name>DmitriyMX</name>
<email>dimon550@gmail.com</email>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<slf4j.version>1.7.21</slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>5.6.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>

2
settings.gradle Normal file
View File

@@ -0,0 +1,2 @@
rootProject.name = 'asys'
include 'core'

View File

@@ -1,24 +0,0 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2017-03-02
*/
package asys.core;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HostActivator implements BundleActivator {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public void start(BundleContext bundleContext) throws Exception {
logger.trace("call [HostActivator.start(BundleContext)]");
}
@Override
public void stop(BundleContext bundleContext) throws Exception {
logger.trace("call [HostActivator.stop(BundleContext)]");
}
}

View File

@@ -1,12 +0,0 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2017-03-02
*/
package asys.core;
public class Main {
public static void main(String[] args) {
Core asysCore = new Core();
asysCore.start();
}
}