@SuppressWarnings("unchecked") private String getSaturnVersion(MavenProject project) throws MojoExecutionException { List<Artifact> artifacts = project.getRuntimeArtifacts(); if (artifacts != null && !artifacts.isEmpty()) { for (int i = 0; i < artifacts.size(); i++) { Artifact artifact = artifacts.get(i); if ("saturn-job-api".equals(artifact.getArtifactId())) { return artifact.getBaseVersion(); } } } throw new MojoExecutionException("cannot read the saturn-job-api dependency."); }
@SuppressWarnings("unchecked") private String getSaturnVersion(MavenProject project) throws MojoExecutionException { List<Artifact> artifacts = project.getRuntimeArtifacts(); if (artifacts != null && !artifacts.isEmpty()) { for (int i = 0; i < artifacts.size(); i++) { Artifact artifact = artifacts.get(i); if ("saturn-job-api".equals(artifact.getArtifactId())) { return artifact.getBaseVersion(); } } } throw new MojoExecutionException("cannot read the saturn-job-api dependency."); }
@SuppressWarnings({ "unchecked" }) @Override public void execute() throws MojoExecutionException, MojoFailureException { if (!CommonUtils.initSaturnHome()) throw new MojoExecutionException("The ${user.home}/.saturn/caches is not exists"); Log log = getLog(); MavenProject project = (MavenProject) getPluginContext().get("project"); String version = getSaturnVersion(project); log.info("Packing the saturn job into a zip file: version:" + version); List<File> runtimeLibFiles = new ArrayList<File>(); List<Artifact> runtimeArtifacts = project.getRuntimeArtifacts(); for (Artifact artifact : runtimeArtifacts) { runtimeLibFiles.add(artifact.getFile()); } runtimeLibFiles.add(new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + "." + project.getPackaging())); File zipFile = new File(project.getBuild().getDirectory(), project.getArtifactId() + "-" + project.getVersion() + "-" + "app.zip"); try { CommonUtils.zip(runtimeLibFiles, null, zipFile); } catch (Exception e) { e.printStackTrace(); throw new MojoExecutionException("zip " + zipFile + " failed", e); } projectHelper.attachArtifact(project, "zip", "executor", zipFile); }
public List<Artifact> getRuntimeArtifacts() { return wrapped.getRuntimeArtifacts(); }
@SuppressWarnings("unchecked") protected void collectProjectArtifactsAndClasspath(List<Artifact> artifacts, List<File> theClasspathFiles) { artifacts.addAll(project.getRuntimeArtifacts()); artifacts.addAll(project.getSystemArtifacts()); theClasspathFiles.add(new File(project.getBuild().getOutputDirectory())); }
private List<Artifact> getClassPath() throws MojoExecutionException { if (alternativeClasspath != null && alternativeClasspath.size() > 0) { return getAlternateClassPath(); } else { return (List<Artifact>)project.getRuntimeArtifacts(); } }
@SuppressWarnings("unchecked") protected void collectProjectArtifactsAndClasspath(List<Artifact> artifacts, List<File> theClasspathFiles) { artifacts.addAll(project.getRuntimeArtifacts()); artifacts.addAll(project.getSystemArtifacts()); theClasspathFiles.add(new File(project.getBuild().getOutputDirectory())); }
public List getRuntimeArtifacts() { return getDelegate().getRuntimeArtifacts(); }
public List<String> keys() { List<String> list = new ArrayList<String>(); list.add(KEY_DEPENDENCIES); MavenProject orig = project.getOriginalMavenProject(); List runtimes = new ArrayList(orig.getRuntimeArtifacts()); runtimes.removeAll(orig.getCompileArtifacts()); if (runtimes.size() > 0) { list.add(KEY_RUNTIME_DEPENDENCIES); } List tests = new ArrayList(orig.getTestArtifacts()); tests.removeAll(orig.getRuntimeArtifacts()); if (tests.size() > 0) { list.add(KEY_TEST_DEPENDENCIES); } return list; }
/** * complete list of classes on project runtime classpath (excluding * jdk bit) * @param project * @return * @throws java.io.IOException */ @SuppressWarnings( "unchecked" ) private Set<String> allProjectClasses( MavenProject project ) throws IOException { Set<String> projectClasses = new HashSet<String>(); DefaultClassAnalyzer analyzer = new DefaultClassAnalyzer(); String outputDirectory = project.getBuild().getOutputDirectory(); URL fl = new File( outputDirectory ).toURI().toURL(); projectClasses.addAll( analyzer.analyze( fl ) ); List<Artifact> libs = project.getRuntimeArtifacts(); for ( Artifact lib : libs ) { URL url = lib.getFile().toURI().toURL(); projectClasses.addAll( analyzer.analyze( url ) ); } return projectClasses; }
/** * Get artifacts for specific scope. * * @param project * @param scope * @return */ private List<Artifact> getScopeArtifacts( final MavenProject project, final String scope ) { if ( SCOPE_COMPILE.equals( scope ) ) { return project.getCompileArtifacts(); } if ( SCOPE_RUNTIME.equals( scope ) ) { return project.getRuntimeArtifacts(); } else if ( SCOPE_TEST.equals( scope ) ) { return project.getTestArtifacts(); } else { throw new RuntimeException( "Not allowed scope " + scope ); } }
/** * complete list of classes on project runtime classpath (excluding * jdk bit) * @param project * @return * @throws java.io.IOException */ @SuppressWarnings( "unchecked" ) private Set<String> allProjectClasses( MavenProject project ) throws IOException { Set<String> projectClasses = new HashSet<String>(); DefaultClassAnalyzer analyzer = new DefaultClassAnalyzer(); String outputDirectory = project.getBuild().getOutputDirectory(); URL fl = new File( outputDirectory ).toURI().toURL(); projectClasses.addAll( analyzer.analyze( fl ) ); List<Artifact> libs = project.getRuntimeArtifacts(); for ( Artifact lib : libs ) { URL url = lib.getFile().toURI().toURL(); projectClasses.addAll( analyzer.analyze( url ) ); } return projectClasses; }
/** * Get artifacts for specific scope. * * @param project * @param scope * @return */ private List<Artifact> getScopeArtifacts( final MavenProject project, final String scope ) { if ( SCOPE_COMPILE.equals( scope ) ) { return project.getCompileArtifacts(); } if ( SCOPE_RUNTIME.equals( scope ) ) { return project.getRuntimeArtifacts(); } else if ( SCOPE_TEST.equals( scope ) ) { return project.getTestArtifacts(); } else { throw new RuntimeException( "Not allowed scope " + scope ); } }
lib.mkdirs(); Collection<Artifact> artifacts = getProject().getRuntimeArtifacts(); for ( Artifact artifact : artifacts )
lib.mkdirs(); Collection<Artifact> artifacts = getProject().getRuntimeArtifacts(); for ( Artifact artifact : artifacts )
private Daemon createDaemon( MavenProject project, ArtifactRepositoryLayout layout, String outputFileNameMapping ) { Daemon complete = new Daemon(); complete.setClasspath( new Classpath() ); // ----------------------------------------------------------------------- // Add the project itself as a dependency. // ----------------------------------------------------------------------- complete.getClasspath().addDependency( DependencyFactory.create( project.getArtifact(), layout, outputFileNameMapping ) ); // ----------------------------------------------------------------------- // Add all the dependencies of the project. // ----------------------------------------------------------------------- for ( Iterator it = project.getRuntimeArtifacts().iterator(); it.hasNext(); ) { Artifact artifact = (Artifact) it.next(); Dependency dependency = DependencyFactory.create( artifact, layout, outputFileNameMapping ); complete.getClasspath().addDependency( dependency ); } return complete; } }
private Daemon createDaemon( MavenProject project, ArtifactRepositoryLayout layout, String outputFileNameMapping ) { Daemon complete = new Daemon(); complete.setClasspath( new Classpath() ); // ----------------------------------------------------------------------- // Add the project itself as a dependency. // ----------------------------------------------------------------------- complete.getClasspath().addDependency( DependencyFactory.create( project.getArtifact(), layout, outputFileNameMapping ) ); // ----------------------------------------------------------------------- // Add all the dependencies of the project. // ----------------------------------------------------------------------- for ( Iterator it = project.getRuntimeArtifacts().iterator(); it.hasNext(); ) { Artifact artifact = (Artifact) it.next(); Dependency dependency = DependencyFactory.create( artifact, layout, outputFileNameMapping ); complete.getClasspath().addDependency( dependency ); } return complete; } }
private void regenerateKeys() { TreeSet lst = new TreeSet(new DependenciesComparator()); if (type == TYPE_COMPILE) { lst.addAll(project.getOriginalMavenProject().getCompileArtifacts()); } if (type == TYPE_TEST) { lst.addAll(project.getOriginalMavenProject().getTestArtifacts()); lst.removeAll(project.getOriginalMavenProject().getCompileArtifacts()); } if (type == TYPE_RUNTIME) { lst.addAll(project.getOriginalMavenProject().getRuntimeArtifacts()); lst.removeAll(project.getOriginalMavenProject().getCompileArtifacts()); } setKeys(lst); } }
private List<Artifact> getArtifacts() { List<Artifact> artifacts = project.getRuntimeArtifacts(); artifacts.addAll(project.getSystemArtifacts()); for (String gem : gems) { if (!gem.endsWith(":")) gem += ":"; ArtifactResolutionRequest request = new ArtifactResolutionRequest(); // TODO instead of transitive just resolve pom and get the // dependency from it // via MavenProject and then resolve the jar dependencies // transitively. or similar. request.setResolveTransitively(true); request.setCollectionFilter(new ArtifactFilter() { public boolean include(Artifact artifact) { return artifact.getDependencyTrail() == null || artifact.getType().equals("jar"); } }); request.setResolveRoot(true); // type pom is enough here request.setArtifact(createArtifact("rubygems:" + gem, "pom")); request.setLocalRepository(localRepository); request.setRemoteRepositories(project .getRemoteArtifactRepositories()); ArtifactResolutionResult result = repositorySystem.resolve(request); artifacts.addAll(result.getArtifacts()); } return artifacts; }
private List<Artifact> getArtifacts() { List<Artifact> artifacts = project.getRuntimeArtifacts(); artifacts.addAll(project.getSystemArtifacts()); for (String gem : gems) { if (!gem.endsWith(":")) gem += ":"; ArtifactResolutionRequest request = new ArtifactResolutionRequest(); // TODO instead of transitive just resolve pom and get the // dependency from it // via MavenProject and then resolve the jar dependencies // transitively. or similar. request.setResolveTransitively(true); request.setCollectionFilter(new ArtifactFilter() { public boolean include(Artifact artifact) { return artifact.getDependencyTrail() == null || artifact.getType().equals("jar"); } }); request.setResolveRoot(true); // type pom is enough here request.setArtifact(createArtifact("rubygems:" + gem, "pom")); request.setLocalRepository(localRepository); request.setRemoteRepositories(project .getRemoteArtifactRepositories()); ArtifactResolutionResult result = repositorySystem.resolve(request); artifacts.addAll(result.getArtifacts()); } return artifacts; }