Переход на Gradle
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -15,10 +15,14 @@ bin/
|
||||
## GRADLE ##
|
||||
.gradle/
|
||||
build/
|
||||
gradle/
|
||||
gradlew
|
||||
gradlew.bat
|
||||
|
||||
## MAVEN ##
|
||||
target/
|
||||
|
||||
## OTHER ##
|
||||
lib/
|
||||
felix-cache/
|
||||
|
||||
|
||||
20
build.gradle
Normal file
20
build.gradle
Normal 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
23
core/build.gradle
Normal 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'
|
||||
}
|
||||
@@ -13,10 +13,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
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 Felix felix;
|
||||
private BundleActivator hostActivator;
|
||||
private Properties properties;
|
||||
|
||||
public Core() {
|
||||
logger.trace("core created");
|
||||
}
|
||||
|
||||
public void setProperties(Properties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void start() {
|
||||
hostActivator = new HostActivator();
|
||||
hostActivator = new HostActivator(properties.getProperty("asys.bundles.dir"));
|
||||
startFelix();
|
||||
}
|
||||
|
||||
@@ -53,6 +55,7 @@ public class Core {
|
||||
config.put("felix.fileinstall.poll", 250);
|
||||
config.put("felix.fileinstall.log.level", 2);
|
||||
config.put("felix.fileinstall.noInitialDelay", true);
|
||||
config.put("org.osgi.framework.system.packages.extra", "com.sun.net.httpserver");
|
||||
|
||||
return ImmutableMap.newInstance(config);
|
||||
}
|
||||
59
core/src/main/java/asys/core/HostActivator.java
Normal file
59
core/src/main/java/asys/core/HostActivator.java
Normal 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)]");
|
||||
}
|
||||
}
|
||||
23
core/src/main/java/asys/core/Main.java
Normal file
23
core/src/main/java/asys/core/Main.java
Normal 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();
|
||||
}
|
||||
}
|
||||
1
core/src/main/resources/asys.properties
Normal file
1
core/src/main/resources/asys.properties
Normal file
@@ -0,0 +1 @@
|
||||
asys.bundles.dir = modules
|
||||
74
pom.xml
74
pom.xml
@@ -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
2
settings.gradle
Normal file
@@ -0,0 +1,2 @@
|
||||
rootProject.name = 'asys'
|
||||
include 'core'
|
||||
@@ -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)]");
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user