Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: hofmeister/Webi
base: 56d46d2cf6
...
head fork: hofmeister/Webi
compare: 0fae525d41
  • 2 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
1  .gitignore
@@ -1 +1,2 @@
target
+.DS_Store
View
80 modules/webi-maven/pom.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ 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>
+
+ <groupId>com.vonhof</groupId>
+ <artifactId>webi-maven</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <properties>
+ <aetherVersion>1.13.1</aetherVersion>
+ <mavenVersion>3.0.3</mavenVersion>
+ <wagonVersion>1.0</wagonVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-api</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-util</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-impl</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-connector-file</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-connector-asynchttpclient</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-connector-wagon</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-aether-provider</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-ssh</artifactId>
+ <version>${wagonVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.5.9</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-settings</artifactId>
+ <version>2.0.6</version>
+ </dependency>
+
+
+
+ </dependencies>
+
+
+</project>
View
197 modules/webi-maven/src/main/java/com/vonhof/webi/maven/Maven.java
@@ -0,0 +1,197 @@
+package com.vonhof.webi.maven;
+
+
+import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader;
+import org.apache.maven.repository.internal.DefaultVersionRangeResolver;
+import org.apache.maven.repository.internal.DefaultVersionResolver;
+import org.apache.maven.repository.internal.MavenRepositorySystemSession;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.sonatype.aether.RepositorySystem;
+import org.sonatype.aether.RepositorySystemSession;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.collection.CollectRequest;
+import org.sonatype.aether.collection.DependencyCollectionException;
+import org.sonatype.aether.connector.async.AsyncRepositoryConnectorFactory;
+import org.sonatype.aether.connector.file.FileRepositoryConnectorFactory;
+import org.sonatype.aether.graph.Dependency;
+import org.sonatype.aether.graph.DependencyNode;
+import org.sonatype.aether.impl.ArtifactDescriptorReader;
+import org.sonatype.aether.impl.VersionRangeResolver;
+import org.sonatype.aether.impl.VersionResolver;
+import org.sonatype.aether.impl.internal.DefaultServiceLocator;
+import org.sonatype.aether.repository.*;
+import org.sonatype.aether.resolution.*;
+import org.sonatype.aether.spi.connector.RepositoryConnectorFactory;
+import org.sonatype.aether.util.artifact.DefaultArtifact;
+import org.sonatype.aether.util.graph.PreorderNodeListGenerator;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Maven {
+ private final DefaultServiceLocator locator = new DefaultServiceLocator();
+
+ private final RepositorySystem repositorySystem;
+ private final LocalRepository localRepo;
+ private final String localRepositoryPath;
+
+ private final LocalRepositoryManager localRepoManager;
+ private final List<RemoteRepository> remoteRepositories = new ArrayList<RemoteRepository>();
+
+ private final MavenWorkspace workspace = new MavenWorkspace("workspace");
+
+ private MavenRepositorySystemSession session;
+
+ public Maven() {
+ String userHome = System.getProperty("user.home");
+
+ localRepositoryPath = userHome+"/.m2/repository/";
+
+ locator.addService(ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class);
+ locator.addService(VersionResolver.class, DefaultVersionResolver.class);
+ locator.addService(VersionRangeResolver.class, DefaultVersionRangeResolver.class);
+ locator.addService(RepositoryConnectorFactory.class, FileRepositoryConnectorFactory.class);
+ locator.addService(RepositoryConnectorFactory.class, AsyncRepositoryConnectorFactory.class);
+
+ repositorySystem = locator.getService(RepositorySystem.class);
+
+ localRepo = new LocalRepository(localRepositoryPath);
+ localRepoManager = repositorySystem.newLocalRepositoryManager(localRepo);
+
+ addRepository("central","http://repo.maven.apache.org/maven2/",true,false);
+ }
+
+
+ /**
+ * Resolve artifact.
+ *
+ * @see Maven::resolveArtifact(String artifactId);
+ *
+ * @param groupId
+ * @param artifactId
+ * @param version
+ * @return
+ * @throws ArtifactResolutionException
+ * @throws DependencyCollectionException
+ */
+ public Artifact resolveArtifact(String groupId,String artifactId,String version) throws ArtifactResolutionException, DependencyCollectionException {
+ return resolveArtifact(String.format("%s:%s:%s",groupId,artifactId,version));
+ }
+
+ /**
+ * Resolve artifact.
+ *
+ * @see Maven::resolveArtifact(String artifactId);
+ *
+ * @param groupId
+ * @param artifactId
+ * @param type
+ * @param version
+ * @return
+ * @throws ArtifactResolutionException
+ * @throws DependencyCollectionException
+ */
+ public Artifact resolveArtifact(String groupId,String artifactId,String type,String version) throws ArtifactResolutionException, DependencyCollectionException {
+ return resolveArtifact(String.format("%s:%s:%s:%s", groupId, artifactId, type, version));
+ }
+
+ /**
+ * Resolve dependencies for artifact - and returns a list of all dependencies as resolved artifacts.
+ *
+ * @param artifactId
+ * @return
+ * @throws DependencyCollectionException
+ * @throws DependencyResolutionException
+ */
+ public List<Artifact> resolveDependencies(String artifactId) throws DependencyCollectionException, DependencyResolutionException, ArtifactResolutionException {
+ Artifact artifact = resolveArtifact(artifactId);
+ Dependency dependency = new Dependency( artifact, "compile" );
+
+ //Collect dependencies
+ CollectRequest collectRequest = new CollectRequest();
+
+ collectRequest.setRoot(dependency);
+ collectRequest.setRepositories(getRemoteRepositories());
+ DependencyNode node = repositorySystem.collectDependencies( session(), collectRequest ).getRoot();
+
+
+ //Resolve dependencies
+ DependencyRequest dependencyRequest = new DependencyRequest( node, null );
+ //dependencyRequest.setCollectRequest(collectRequest);
+ repositorySystem.resolveDependencies( session(), dependencyRequest);
+
+ //Order result
+ PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
+ node.accept( nlg );
+ return nlg.getArtifacts(true);
+ }
+
+ /**
+ * Resolve artifact by id. Downloads artifact from remote repository if needed.
+ * Returned artifact instance has contains file pointer to locale file.
+ *
+ * @param artifactId
+ * @return
+ * @throws ArtifactResolutionException
+ * @throws DependencyCollectionException
+ */
+ public Artifact resolveArtifact(String artifactId) throws ArtifactResolutionException, DependencyCollectionException {
+
+ Artifact artifact = new DefaultArtifact(artifactId);
+ Dependency dependency = new Dependency( artifact, "compile" );
+
+ //Resolve artifact
+ ArtifactRequest artifactRequest = new ArtifactRequest();
+ artifactRequest.setArtifact(artifact);
+ artifactRequest.setRepositories(getRemoteRepositories());
+ final ArtifactResult result = repositorySystem.resolveArtifact(session(), artifactRequest);
+
+ return result.getArtifact();
+ }
+
+ public void addRepository(String id,String url) {
+ addRepository(id,url,true,true);
+ }
+
+ public void addRepository(String id,String url,boolean release) {
+ addRepository(id,url,release,true);
+ }
+
+ /**
+ * Add remote repository. Maven central is added automatically.
+ * @param id
+ * @param url
+ */
+ public void addRepository(String id,String url,boolean release,boolean snapshots) {
+ final RemoteRepository repo = new RemoteRepository(id, "default", url);
+
+ repo.setPolicy(false,new RepositoryPolicy().setEnabled(release));
+ repo.setPolicy(true,new RepositoryPolicy().setEnabled(snapshots));
+
+ remoteRepositories.add(repo);
+ }
+
+ /**
+ * Add workspace artifact to this maven instance. Will overwrite everything else for that particular artifact.
+ * @param artifact
+ */
+ public void addArtifact(Artifact artifact) {
+ workspace.addArtifact(artifact);
+ }
+
+ protected List<RemoteRepository> getRemoteRepositories() {
+ return remoteRepositories;
+ }
+
+ protected RepositorySystemSession session() {
+ if (session == null) {
+ session = new MavenRepositorySystemSession();
+ session.setLocalRepositoryManager(localRepoManager);
+ session.setWorkspaceReader(workspace);
+ }
+
+ return session;
+ }
+}
View
57 modules/webi-maven/src/main/java/com/vonhof/webi/maven/MavenWorkspace.java
@@ -0,0 +1,57 @@
+package com.vonhof.webi.maven;
+
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.repository.WorkspaceReader;
+import org.sonatype.aether.repository.WorkspaceRepository;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class MavenWorkspace implements WorkspaceReader {
+ private final WorkspaceRepository workspaceRepository;
+ private Map<String,Map<String,Map<String,Artifact>>> artifacts = new HashMap<String, Map<String, Map<String, Artifact>>>();
+
+ public MavenWorkspace(String id) {
+ workspaceRepository = new WorkspaceRepository(id);
+ }
+
+ @Override
+ public WorkspaceRepository getRepository() {
+ return workspaceRepository;
+ }
+
+ @Override
+ public File findArtifact(Artifact artifact) {
+ final Map<String, Artifact> versions = getVersions(artifact.getGroupId(), artifact.getArtifactId());
+
+ final Artifact version = versions.get(artifact.getVersion());
+ if (version == null) {
+ return null;
+ }
+
+ return version.getFile();
+ }
+
+ @Override
+ public List<String> findVersions(Artifact artifact) {
+ return new ArrayList<String>(getVersions(artifact.getGroupId(),artifact.getArtifactId()).keySet());
+ }
+
+ public void addArtifact(Artifact artifact) {
+ final Map<String, Artifact> versions = getVersions(artifact.getGroupId(), artifact.getArtifactId());
+ versions.put(artifact.getVersion(),artifact);
+ }
+
+ private Map<String,Artifact> getVersions(String groupId,String artifactId) {
+ if (!artifacts.containsKey(groupId)) {
+ artifacts.put(groupId,new HashMap<String, Map<String, Artifact>>());
+ }
+ if (!artifacts.get(groupId).containsKey(artifactId)) {
+ artifacts.get(groupId).put(artifactId,new HashMap<String, Artifact>());
+ }
+ return artifacts.get(groupId).get(artifactId);
+ }
+}
View
51 modules/webi-maven/src/test/java/com/vonhof/webi/maven/MavenTest.java
@@ -0,0 +1,51 @@
+package com.vonhof.webi.maven;
+
+import org.junit.Test;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.util.artifact.DefaultArtifact;
+
+import java.io.File;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+public class MavenTest {
+
+ @Test
+ public void testResolveArtifact() throws Exception {
+ Maven mvn = new Maven();
+ final Artifact artifact = mvn.resolveArtifact("com.hazelcast:hazelcast:2.5");
+
+ assertNotNull(artifact);
+ assertTrue(artifact.getFile().exists());
+
+ }
+
+
+ @Test
+ public void testResolveDependencies() throws Exception {
+ Maven mvn = new Maven();
+
+ final List<Artifact> artifacts = mvn.resolveDependencies("org.springframework:spring-core:3.2.1.RELEASE");
+
+ assertTrue(artifacts.size() > 1);
+ }
+
+ @Test
+ public void testAddArtifact() throws Exception {
+ Maven mvn = new Maven();
+
+ Artifact artifact = new DefaultArtifact("com.example:nothing:6.6.6")
+ .setFile(new File("com/example/nothing-6.6.6.jar"));
+
+ mvn.addArtifact(artifact);
+
+ Artifact resolvedArtifact = mvn.resolveArtifact("com.example:nothing:6.6.6");
+
+ assertNotNull(resolvedArtifact);
+ }
+
+ private File file(String path) {
+ return new File(getClass().getResource(path).getFile());
+ }
+}
View
18 modules/webi-maven/src/test/resources/testpom.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ 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>
+
+ <groupId>com.testgroup</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.0.4</version>
+ </dependency>
+ </dependencies>
+</project>
View
47 modules/webi-maven/webi-maven.iml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
+ </content>
+ <orderEntry type="jdk" jdkName="1.6" jdkType="JavaSDK" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="Maven: org.sonatype.aether:aether-api:1.13.1" level="project" />
+ <orderEntry type="library" name="Maven: org.sonatype.aether:aether-util:1.13.1" level="project" />
+ <orderEntry type="library" name="Maven: org.sonatype.aether:aether-impl:1.13.1" level="project" />
+ <orderEntry type="library" name="Maven: org.sonatype.aether:aether-spi:1.13.1" level="project" />
+ <orderEntry type="library" name="Maven: org.sonatype.aether:aether-connector-file:1.13.1" level="project" />
+ <orderEntry type="library" name="Maven: org.sonatype.aether:aether-connector-asynchttpclient:1.13.1" level="project" />
+ <orderEntry type="library" name="Maven: com.ning:async-http-client:1.6.5" level="project" />
+ <orderEntry type="library" name="Maven: org.jboss.netty:netty:3.2.5.Final" level="project" />
+ <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.6.2" level="project" />
+ <orderEntry type="library" name="Maven: org.sonatype.aether:aether-connector-wagon:1.13.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.maven.wagon:wagon-provider-api:1.0-beta-6" level="project" />
+ <orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-utils:1.5.9" level="project" />
+ <orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-classworlds:2.4" level="project" />
+ <orderEntry type="library" name="Maven: org.sonatype.sisu:sisu-inject-plexus:2.2.3" level="project" />
+ <orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-component-annotations:1.5.5" level="project" />
+ <orderEntry type="library" name="Maven: org.sonatype.sisu:sisu-inject-bean:2.2.3" level="project" />
+ <orderEntry type="library" name="Maven: org.sonatype.sisu:sisu-guice:no_aop:3.0.3" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.maven:maven-aether-provider:3.0.3" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.maven:maven-model:3.0.3" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.maven:maven-model-builder:3.0.3" level="project" />
+ <orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-interpolation:1.14" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.maven:maven-repository-metadata:3.0.3" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.maven.wagon:wagon-ssh:1.0" level="project" />
+ <orderEntry type="library" name="Maven: com.jcraft:jsch:0.1.44-1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.maven.wagon:wagon-ssh-common:1.0" level="project" />
+ <orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-interactivity-api:1.0-alpha-6" level="project" />
+ <orderEntry type="library" name="Maven: junit:junit:4.8.2" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.maven:maven-settings:2.0.6" level="project" />
+ <orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-container-default:1.0-alpha-9-stable-1" level="project" />
+ <orderEntry type="library" name="Maven: classworlds:classworlds:1.1-alpha-2" level="project" />
+ </component>
+</module>
+
View
2  src/main/java/com/vonhof/webi/PathPatternMap.java
@@ -63,4 +63,6 @@ protected String trimContext(String path) {
return map.entrySet();
}
+
+
}
View
7 src/main/java/com/vonhof/webi/Webi.java
@@ -2,6 +2,7 @@
import com.vonhof.babelshark.BabelShark;
import com.vonhof.webi.bean.BeanContext;
+import com.vonhof.webi.file.FileRequestHandler;
import com.vonhof.webi.session.SessionHandler;
import java.io.IOException;
import java.util.ArrayList;
@@ -184,6 +185,7 @@ public void run() {
beanContext.add(handler);
return handler;
}
+
/**
* Add filter at path
@@ -205,8 +207,7 @@ public void add(ShutdownHandler shutdownHandler) {
/**
* Add session resolver at path
- * @param path
- * @param handler
+ * @param handler
*/
public <T extends SessionHandler> T add(T handler) {
sessionHandlers.put(handler.getBasePath(), handler);
@@ -232,7 +233,7 @@ public void addBean(String id, Object obj) {
public BeanContext getBeanContext() {
return beanContext;
}
-
+
/**
* Internal webi jetty handler
*/
View
7 src/main/java/com/vonhof/webi/rest/RESTServiceHandler.java
@@ -61,7 +61,7 @@ public UrlMapper getUrlMapper() {
public void expose(Object obj) {
urlMapper.expose(obj);
webi.addBean(obj);
- };
+ }
public void expose(Object obj, String baseUrl) {
urlMapper.expose(obj, baseUrl);
@@ -71,8 +71,9 @@ public void expose(Object obj, String baseUrl) {
public void expose(String id,Object obj) {
urlMapper.expose(obj);
webi.addBean(id,obj);
- };
-
+ }
+
+
@Override
public void handle(WebiContext ctxt) throws IOException, ServletException {

No commit comments for this range

Something went wrong with that request. Please try again.