+ }\r
+ /*\r
+ * private final Log log = LogFactory.getLog(getClass());\r
+ * \r
+ * private String localRepositoryPath = System.getProperty("user.home") +\r
+ * File.separator + ".m2" + File.separator + "repository";\r
+ * \r
+ * private ArtifactRepository localRepository; private\r
+ * List<ArtifactRepository> remoteRepositoriesInternal; private\r
+ * List<RemoteRepository> remoteRepositories = new\r
+ * Vector<RemoteRepository>();\r
+ * \r
+ * private MavenEmbedder mavenEmbedder; private ClassLoader classLoader;\r
+ * private Boolean offline = false;\r
+ * \r
+ * public void init() { try { mavenEmbedder = new SlcMavenEmbedder();\r
+ * mavenEmbedder.setOffline(offline); //\r
+ * mavenEmbedder.setAlignWithUserInstallation(true); if (classLoader !=\r
+ * null) mavenEmbedder.setClassLoader(classLoader); else\r
+ * mavenEmbedder.setClassLoader(getClass().getClassLoader()); // else //\r
+ * mavenEmbedder.setClassLoader(Thread.currentThread() //\r
+ * .getContextClassLoader()); mavenEmbedder.start();\r
+ * \r
+ * mavenEmbedder.setLocalRepositoryDirectory(new File(\r
+ * localRepositoryPath));\r
+ * \r
+ * localRepository = mavenEmbedder.getLocalRepository();\r
+ * \r
+ * remoteRepositoriesInternal = new Vector<ArtifactRepository>(); for\r
+ * (RemoteRepository remoteRepository : remoteRepositories) {\r
+ * \r
+ * ArtifactRepository repository = mavenEmbedder.createRepository(\r
+ * remoteRepository.getUrl(), remoteRepository.getId());\r
+ * remoteRepositoriesInternal.add(repository); }\r
+ * \r
+ * MavenFile mavenFile = new MavenFile();\r
+ * mavenFile.setGroupId("org.argeo.slc.dist");\r
+ * mavenFile.setArtifactId("org.argeo.slc.sdk");\r
+ * mavenFile.setVersion("0.12.2-SNAPSHOT"); mavenFile.setType("pom");\r
+ * Artifact artifact = resolve(mavenFile); log.debug("Location of " +\r
+ * artifact + " : " + artifact.getFile()); // log.debug("Dependencies of " +\r
+ * artifact); // for (Object obj : artifact.getDependencyTrail()) { //\r
+ * log.debug(" " + obj); // }\r
+ * \r
+ * File pomFile = new File(\r
+ * "/home/mbaudier/dev/src/slc/dist/org.argeo.slc.sdk/pom.xml");\r
+ * MavenProject project = mavenEmbedder\r
+ * .readProjectWithDependencies(pomFile); // MavenProject project =\r
+ * mavenEmbedder // .readProjectWithDependencies(artifact.getFile());\r
+ * \r
+ * // EventMonitor eventMonitor = new EventMonitor() { // // public void\r
+ * startEvent(String eventName, String target, // long timestamp) { //\r
+ * log.debug(eventName + ", " + target + ", " + timestamp); // } // //\r
+ * public void errorEvent(String eventName, String target, // long\r
+ * timestamp, Throwable cause) { // log.debug(eventName + ", " + target +\r
+ * ", " + timestamp); // } // // public void endEvent(String eventName,\r
+ * String target, // long timestamp) { // log.debug(eventName + ", " +\r
+ * target + ", " + timestamp); // } // }; // // String[] goals = { "clean",\r
+ * "install" }; // mavenEmbedder.execute(project, Arrays.asList(goals), //\r
+ * eventMonitor, // null, null, pomFile.getParentFile());\r
+ * \r
+ * Set<Artifact> transitDeps = getTransitiveProjectDependencies( project,\r
+ * remoteRepositoriesInternal, localRepository);\r
+ * log.debug(transitDeps.size() + " dependencies for " + artifact); for\r
+ * (Object obj : transitDeps) { log.debug(" " + obj); }\r
+ * \r
+ * } catch (Exception e) { throw new\r
+ * SlcException("Cannot initialize Maven manager", e); } }\r
+ * \r
+ * @SuppressWarnings("unchecked") public Set<Artifact>\r
+ * getTransitiveProjectDependencies(MavenProject project,\r
+ * List<ArtifactRepository> remoteRepos, ArtifactRepository local) {\r
+ * Embedder embedder = mavenEmbedder.getEmbedder(); try { ArtifactFactory\r
+ * artifactFactory = (ArtifactFactory) embedder\r
+ * .lookup(ArtifactFactory.ROLE);\r
+ * \r
+ * ArtifactResolver artifactResolver = (ArtifactResolver) embedder\r
+ * .lookup(ArtifactResolver.ROLE);\r
+ * \r
+ * ArtifactMetadataSource artifactMetadataSource = (ArtifactMetadataSource)\r
+ * embedder .lookup(ArtifactMetadataSource.ROLE);\r
+ * \r
+ * Set<Artifact> artifacts = project.createArtifacts(artifactFactory, null,\r
+ * null);\r
+ * \r
+ * ArtifactResolutionResult arr = artifactResolver\r
+ * .resolveTransitively(artifacts, project.getArtifact(), local,\r
+ * remoteRepos, artifactMetadataSource, null);\r
+ * \r
+ * return arr.getArtifacts(); } catch (Exception e) { throw new\r
+ * SlcException("Cannot resolve dependency for " + project, e); } // Order,\r
+ * just for display // Set dependencies = new TreeSet(new\r
+ * ArtifactComparator()); // dependencies.addAll(arr.getArtifacts()); //\r
+ * return dependencies; }\r
+ * \r
+ * private Artifact resolve(MavenFile mavenDistribution) { try { Artifact\r
+ * artifact; if (mavenDistribution.getClassifier() == null) { artifact =\r
+ * mavenEmbedder.createArtifact(mavenDistribution .getGroupId(),\r
+ * mavenDistribution.getArtifactId(), mavenDistribution.getVersion(),\r
+ * Artifact.SCOPE_PROVIDED, mavenDistribution.getType()); } else { artifact\r
+ * = mavenEmbedder.createArtifactWithClassifier(\r
+ * mavenDistribution.getGroupId(), mavenDistribution .getArtifactId(),\r
+ * mavenDistribution .getVersion(), mavenDistribution.getType(),\r
+ * mavenDistribution.getClassifier()); }\r
+ * \r
+ * mavenEmbedder.resolve(artifact, remoteRepositoriesInternal,\r
+ * localRepository);\r
+ * \r
+ * return artifact; } catch (Exception e) { throw new\r
+ * SlcException("Cannot resolve artifact.", e); } }\r
+ * \r
+ * public File getPackageLocation(MavenFile mavenDistribution) { return\r
+ * resolve(mavenDistribution).getFile(); }\r
+ * \r
+ * public void destroy() { try { if (mavenEmbedder != null) {\r
+ * mavenEmbedder.stop(); } } catch (MavenEmbedderException e) {\r
+ * log.error("Cannot destroy Maven manager", e); } }\r
+ * \r
+ * public void setLocalRepositoryPath(String localRepositoryPath) {\r
+ * this.localRepositoryPath = localRepositoryPath; }\r
+ * \r
+ * public List<RemoteRepository> getRemoteRepositories() { return\r
+ * remoteRepositories; }\r
+ * \r
+ * public void setRemoteRepositories(List<RemoteRepository>\r
+ * remoteRepositories) { this.remoteRepositories = remoteRepositories; }\r
+ * \r
+ * public void setClassLoader(ClassLoader classLoader) { this.classLoader =\r
+ * classLoader; }\r
+ * \r
+ * public void setOffline(Boolean offline) { this.offline = offline; }\r
+ */\r