private List<URL> generateExecutionClasspath( Set<Artifact> resolvedArtifacts, String... excludeGroups) throws MojoExecutionException { /* * Convert each resolved artifact into a URL/classpath element. */ final ArrayList<URL> classpath = new ArrayList<URL>(); final List<String> excludes = Arrays.asList(excludeGroups); try { for (Artifact resolvedArtifact : resolvedArtifacts) { if (excludes.contains(resolvedArtifact.getGroupId())) continue; final File file = resolvedArtifact.getFile(); // System.out.println("artifact " + resolvedArtifact.toString()); if (file != null) { if (artifactIdsToInsertAtStartOfClasspath.contains(resolvedArtifact.getArtifactId())) { getLog().info("adding at the start" + file.getAbsolutePath()); // a patch? grails is full of them, insert it at the start classpath.add(0, file.toURI().toURL()); } else { // insert it at the end classpath.add(file.toURI().toURL()); } } } } catch (MalformedURLException murle) { throw new MojoExecutionException("Unable to find files", murle); } return classpath; }
String getBundleClasspath() throws MojoExecutionException { StringBuffer sb = new StringBuffer(); File outputDirectory = new File(project.getBuild().getOutputDirectory()); if (outputDirectory.exists()) { if (classifier != null) { for (Iterator i = project.getAttachedArtifacts().iterator(); i.hasNext(); ) { Artifact a = (Artifact) i.next(); if (classifier.equals(a.getClassifier())) { sb.append(jars + "/" + a.getFile().getName()); } } } else if (projectJar != null) { sb.append(jars + "/" + projectJar); } } if (bundleClasspath != null) { for (int i = 0; i < bundleClasspath.length; i++) { if (sb.length() > 0) sb.append(','); sb.append(bundleClasspath[i]); } } for (Iterator i = getIncludedArtifacts().iterator(); i.hasNext(); ) { Artifact a = (Artifact) i.next(); if (sb.length() > 0) sb.append(','); sb.append(jars + "/" + a.getFile().getName()); } return sb.toString(); }
private void addDependencies(final MavenProject project, final JettyWebAppContext webAppConfig) throws Exception { List<File> dependencyFiles = new ArrayList<File>(); List<Resource> overlays = new ArrayList<Resource>(); for (Artifact artifact : project.getArtifacts()) { if (artifact.getType().equals("war")) { overlays.add(Resource.newResource("jar:" + artifact.getFile().toURL().toString() + "!/")); } else if ((!Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) && (!Artifact.SCOPE_TEST.equals(artifact.getScope()))) { File dependencyFile = artifact.getFile(); if (dependencyFile == null || !dependencyFile.exists()) { String coordinates = String.format( "%s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); LOG.log( Level.WARNING, "Dependency '" + coordinates + "' does not exist in repository. Skipping!"); continue; } dependencyFiles.add(artifact.getFile()); } } webAppConfig.setOverlays(overlays); webAppConfig.setWebInfLib(dependencyFiles); }
private void copyNativeLibraryArtifactFileToDirectory( Artifact artifact, File destinationDirectory, String ndkArchitecture) throws MojoExecutionException { final File artifactFile = getArtifactResolverHelper().resolveArtifactToFile(artifact); try { final String artifactId = artifact.getArtifactId(); String filename = artifactId.startsWith("lib") ? artifactId + ".so" : "lib" + artifactId + ".so"; if (ndkFinalLibraryName != null && artifact.getFile().getName().startsWith("lib" + ndkFinalLibraryName)) { // The artifact looks like one we built with the NDK in this module // preserve the name from the NDK build filename = artifact.getFile().getName(); } final File finalDestinationDirectory = getFinalDestinationDirectoryFor(artifact, destinationDirectory, ndkArchitecture); final File file = new File(finalDestinationDirectory, filename); getLog() .debug( "Copying native dependency " + artifactId + " (" + artifact.getGroupId() + ") to " + file); FileUtils.copyFile(artifactFile, file); } catch (Exception e) { throw new MojoExecutionException("Could not copy native dependency.", e); } }
private void createClasspathJarFile(File lib) throws Exception { getLog().info("[WarSync] Create warsync-classpath.jar in " + lib.getAbsolutePath()); List<String> jarFiles = new ArrayList<String>(); if (artifacts != null && !artifacts.isEmpty()) { for (Artifact artifact : artifacts) { if (getLog().isDebugEnabled()) { getLog().debug("[WarSync] Found dependency: " + artifact.getId()); } if (isLib(artifact)) { if (getLog().isDebugEnabled()) { getLog() .debug( "[WarSync] Add " + artifact.getFile().toURI().getPath() + " to Class-Path entry of MANIFEST.MF"); } jarFiles.add(artifact.getFile().toURI().getPath()); } } } JarArchiver jar = new JarArchiver(); jar.setDestFile(new File(lib, "warsync-classpath.jar")); Manifest manifest = Manifest.getDefaultManifest(); manifest.addConfiguredAttribute(new Manifest.Attribute("Created-By", "maven-warsync-plugin")); manifest.addConfiguredAttribute( new Manifest.Attribute("Built-By", System.getProperty("user.name"))); manifest.addConfiguredAttribute( new Manifest.Attribute("Build-Jdk", System.getProperty("java.version"))); if (!jarFiles.isEmpty()) { manifest.addConfiguredAttribute( new Manifest.Attribute("Class-Path", StringUtils.join(jarFiles.iterator(), " "))); } jar.addConfiguredManifest(manifest); jar.createArchive(); }
@Override protected List<File> getDependencies() { ArrayList<File> dependencies = new ArrayList<File>(); @SuppressWarnings("unchecked") final Iterator<Artifact> it = project.getArtifacts().iterator(); while (it.hasNext()) { final Artifact declared = it.next(); this.log.debug("Checking artifact " + declared); if (this.isJavaArtifact(declared)) { if (Artifact.SCOPE_COMPILE.equals(declared.getScope()) || Artifact.SCOPE_RUNTIME.equals(declared.getScope()) || Artifact.SCOPE_PROVIDED.equals(declared.getScope()) || Artifact.SCOPE_SYSTEM.equals(declared.getScope())) { this.log.debug("Resolving artifact " + declared); if (declared.getFile() != null) { dependencies.add(declared.getFile()); } else { this.log.debug("Unable to resolve artifact " + declared); } } else { this.log.debug( "Artifact " + declared + " has not scope compile or runtime, but " + declared.getScope()); } } else { this.log.debug( "Artifact " + declared + " is not a java artifact, type is " + declared.getType()); } } return dependencies; }
/** @return */ private List<File> getDependencyFiles() { List<File> dependencyFiles = new ArrayList<File>(); for (Iterator<Artifact> iter = projectArtifacts.iterator(); iter.hasNext(); ) { Artifact artifact = (Artifact) iter.next(); // Include runtime and compile time libraries, and possibly test libs too if (artifact.getType().equals("war")) { continue; } if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) continue; // never add dependencies of scope=provided to the webapp's classpath (see also // <useProvidedScope> param) if (Artifact.SCOPE_TEST.equals(artifact.getScope()) && !useTestScope) continue; // only add dependencies of scope=test if explicitly required dependencyFiles.add(artifact.getFile()); getLog() .debug( "Adding artifact " + artifact.getFile().getName() + " with scope " + artifact.getScope() + " for WEB-INF/lib "); } return dependencyFiles; }
/** * Main entry into mojo. This method gets the dependencies and iterates through each one passing * it to DependencyUtil.unpackFile(). * * @throws MojoExecutionException with a message if an error occurs. * @see #getDependencies * @see DependencyUtil#unpackFile(Artifact, File, File, ArchiverManager, Log) */ public void execute() throws MojoExecutionException { DependencyStatusSets dss = getDependencySets(this.failOnMissingClassifierArtifact); Set artifacts = dss.getResolvedDependencies(); for (Iterator i = artifacts.iterator(); i.hasNext(); ) { Artifact artifact = (Artifact) i.next(); File destDir; destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerType, useSubDirectoryPerArtifact, useRepositoryLayout, stripVersion, outputDirectory, artifact); unpack(artifact.getFile(), destDir, getIncludes(), getExcludes()); DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler(artifact, this.markersDirectory); handler.setMarker(); } artifacts = dss.getSkippedDependencies(); for (Iterator i = artifacts.iterator(); i.hasNext(); ) { Artifact artifact = (Artifact) i.next(); getLog().info(artifact.getFile().getName() + " already exists in destination."); } }
protected File[] getGwtUserJar() throws MojoExecutionException { checkGwtUserVersion(); Artifact gwtUserArtifact = getArtifact("com.google.gwt", "gwt-user"); Set<Artifact> artifacts = new HashSet<Artifact>(); ArtifactResolutionResult result = null; try { result = resolver.resolveTransitively( artifacts, gwtUserArtifact, remoteRepositories, localRepository, artifactMetadataSource); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Failed to resolve artifact", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Failed to resolve artifact", e); } Collection<Artifact> resolved = result.getArtifacts(); int i = 0; // FIXME gwt 2.3.0 don't declare dependency on javax.validation, should be fix in next release File[] files = new File[resolved.size() + 1 + 2]; files[i++] = gwtUserArtifact.getFile(); for (Artifact artifact : resolved) { files[i++] = artifact.getFile(); } files[i++] = getArtifact("javax.validation", "validation-api").getFile(); files[i++] = getArtifact("javax.validation", "validation-api", "sources").getFile(); return files; }
/** * @return * @throws Exception */ public String getClassPath() throws Exception { StringBuilder classPath = new StringBuilder(); for (Object obj : pluginArtifacts) { Artifact artifact = (Artifact) obj; if ("jar".equals(artifact.getType())) { if (classPath.length() > 0) { classPath.append(File.pathSeparator); } classPath.append(artifact.getFile().getAbsolutePath()); } } // Any jars that we need from the plugin environment (like the ones containing Starter class) Set<Artifact> extraJars = getExtraJars(); for (Artifact a : extraJars) { classPath.append(File.pathSeparator); classPath.append(a.getFile().getAbsolutePath()); } // Any jars that we need from the project's dependencies because we're useProvided List<String> providedJars = getProvidedJars(); if (providedJars != null && !providedJars.isEmpty()) { for (String jar : providedJars) { classPath.append(File.pathSeparator); classPath.append(jar); if (getLog().isDebugEnabled()) getLog().debug("Adding provided jar: " + jar); } } return classPath.toString(); }
/** * Set up the execution classpath for Jasper. * * <p>Put everything in the classesDirectory and all of the dependencies on the classpath. * * @returns a list of the urls of the dependencies * @throws Exception */ private List<URL> setUpWebAppClassPath() throws Exception { // add any classes from the webapp List<URL> urls = new ArrayList<URL>(); String classesDir = classesDirectory.getCanonicalPath(); classesDir = classesDir + (classesDir.endsWith(File.pathSeparator) ? "" : File.separator); urls.add(Resource.toURL(new File(classesDir))); if (getLog().isDebugEnabled()) getLog().debug("Adding to classpath classes dir: " + classesDir); // add the dependencies of the webapp (which will form WEB-INF/lib) for (Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); ) { Artifact artifact = (Artifact) iter.next(); // Include runtime and compile time libraries if (!Artifact.SCOPE_TEST.equals(artifact.getScope()) && !Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) { String filePath = artifact.getFile().getCanonicalPath(); if (getLog().isDebugEnabled()) getLog().debug("Adding to classpath dependency file: " + filePath); urls.add(Resource.toURL(artifact.getFile())); } } return urls; }
public void test005_snapshotAvailableFromLocalRepoAndWorkspace() throws Exception { IProject p1 = createExisting("t005-p3"); waitForJobsToComplete(); { IMavenProjectFacade f = manager.create(p1, monitor); Set<Artifact> artifacts = getMavenProjectArtifacts(f); assertEquals(1, artifacts.size()); Artifact a = artifacts.iterator().next(); assertEquals(true, a.isResolved()); // assertTrue(a.getFile().getAbsolutePath().startsWith(repo.getAbsolutePath())); assertStartWith(repo.getAbsolutePath(), a.getFile().getAbsolutePath()); } IProject p2 = createExisting("t005-p4"); waitForJobsToComplete(); { IMavenProjectFacade f = manager.create(p1, monitor); Set<Artifact> artifacts = getMavenProjectArtifacts(f); assertEquals(1, artifacts.size()); Artifact a = artifacts.iterator().next(); assertEquals(true, a.isResolved()); assertEquals(p2.getFile(IMavenConstants.POM_FILE_NAME).getLocation().toFile(), a.getFile()); } }
/** * Resolve source artifacts and download them if <code>downloadSources</code> is <code>true</code> * . Source and javadocs artifacts will be attached to the <code>IdeDependency</code> * * @param deps resolved dependencies */ private void resolveSourceArtifacts(IdeDependency[] deps) { ArtifactRepository localRepository = getLocalRepository(); ArtifactResolver artifactResolver = getArtifactResolver(); ArtifactFactory artifactFactory = getArtifactFactory(); // if downloadSources is off, just check local repository for reporting missing jars List remoteRepos = getDownloadSources() ? getRemoteArtifactRepositories() : Collections.EMPTY_LIST; for (int j = 0; j < deps.length; j++) { IdeDependency dependency = deps[j]; if (dependency.isReferencedProject() || dependency.isSystemScoped()) { // source artifact not needed continue; } // source artifact: use the "sources" classifier added by the source plugin Artifact sourceArtifact = IdeUtils.resolveArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), "sources", localRepository, artifactResolver, //$NON-NLS-1$ artifactFactory, remoteRepos, getLog()); if (sourceArtifact.isResolved()) { dependency.setSourceAttachment(sourceArtifact.getFile()); } else { // try using a plain javadoc jar if the source jar is not available Artifact javadocArtifact = IdeUtils.resolveArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), "javadoc", localRepository, artifactResolver, //$NON-NLS-1$ artifactFactory, remoteRepos, getLog()); if (javadocArtifact.isResolved()) { dependency.setJavadocAttachment(javadocArtifact.getFile()); } // @todo also report deps without a source attachment but with a javadoc one? missingSourceDependencies.add(dependency); } } }
/** * Returns a map from classifiers to artifact files of the given project. The classifier <code> * null</code> is mapped to the project's main artifact. */ private static Map<String, File> getAllProjectArtifacts(MavenProject project) { Map<String, File> artifacts = new HashMap<String, File>(); Artifact mainArtifact = project.getArtifact(); if (mainArtifact != null) { artifacts.put(null, mainArtifact.getFile()); } for (Artifact attachedArtifact : project.getAttachedArtifacts()) { artifacts.put(attachedArtifact.getClassifier(), attachedArtifact.getFile()); } return artifacts; }
/** * @param artifactKey * @return * @throws ArtifactNotFoundException */ private FileResource resolveFile(String artifactKey) throws ArtifactNotFoundException { ArtifactDescriptor ad = new ArtifactDescriptor(artifactKey); if (classifier != null) { ad.classifier = classifier; } Artifact artifact = ad.getArtifact(); MavenClientFactory.getInstance().resolve(artifact); FileResource fr = new FileResource(artifact.getFile()); fr.setBaseDir(artifact.getFile().getParentFile()); return fr; }
private void addDependencies(List<URL> urls) throws MalformedURLException, MojoExecutionException { FilterArtifacts filters = this.useTestClasspath ? getFilters() : getFilters(new TestArtifactFilter()); Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(), filters); for (Artifact artifact : artifacts) { if (artifact.getFile() != null) { urls.add(artifact.getFile().toURI().toURL()); } } }
/** * Converts a collection of Maven artifacts to files. For this method to function properly, the * artifacts MUST be resolved first. * * @param artifacts A collection of artifacts. * @return The list of files pointed to by the artifacts. */ private List<File> artifactsToFiles(final Collection<Artifact> artifacts) { final List<File> files = new ArrayList<File>(artifacts.size()); StringBuilder sb = new StringBuilder(); for (Artifact artifact : artifacts) { sb.append("\natof " + artifact.getFile().getAbsolutePath()); files.add(artifact.getFile()); } if (logDependencies) getLog().info(sb.toString()); return files; }
/** * Resolve the artifacts represented by the given collection of JarResources and copy them to the * working directory if a newer copy of the file doesn't already exist there. Transitive * dependencies will also be retrieved. * * <p>Transitive dependencies are added to the list specified as parameter. TODO fix that. * * @throws MojoExecutionException */ private void retrieveJarResources(List jarResources) throws MojoExecutionException { Set jarResourceArtifacts = new HashSet(); try { // for each configured JarResource, create and resolve the corresponding artifact and // check it for the mainClass if specified for (Iterator itr = jarResources.iterator(); itr.hasNext(); ) { JarResource jarResource = (JarResource) itr.next(); Artifact artifact = createArtifact(jarResource); getArtifactResolver().resolve(artifact, getRemoteRepositories(), getLocalRepository()); jarResource.setArtifact(artifact); checkForMainClass(jarResource); jarResourceArtifacts.add(artifact); } if (!isExcludeTransitive()) { retrieveTransitiveDependencies(jarResourceArtifacts, jarResources); } // for each JarResource, copy its artifact to the lib directory if necessary for (Iterator itr = jarResources.iterator(); itr.hasNext(); ) { JarResource jarResource = (JarResource) itr.next(); Artifact artifact = jarResource.getArtifact(); boolean copied = copyJarAsUnprocessedToDirectoryIfNecessary(artifact.getFile(), getLibDirectory()); if (copied) { String name = artifact.getFile().getName(); if (getLog().isDebugEnabled()) { getLog().debug("Adding " + name + " to modifiedJnlpArtifacts list."); } getModifiedJnlpArtifacts().add(name.substring(0, name.lastIndexOf('.'))); } if (jarResource.isOutputJarVersion()) { // Create and set a version-less href for this jarResource String hrefValue = buildHrefValue(artifact); jarResource.setHrefValue(hrefValue); } } } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Unable to resolve an artifact", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Unable to find an artifact", e); } catch (IOException e) { throw new MojoExecutionException("Unable to copy an artifact to the working directory", e); } }
private void addArtifact(SurefireBooter surefireBooter, Artifact surefireArtifact) throws ArtifactNotFoundException, ArtifactResolutionException { ArtifactResolutionResult result = resolveArtifact(null, surefireArtifact); for (Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) { Artifact artifact = (Artifact) i.next(); getLog() .debug( "Adding to surefire booter test classpath: " + artifact.getFile().getAbsolutePath()); surefireBooter.addSurefireBootClassPathUrl(artifact.getFile().getAbsolutePath()); } }
public void testWorkspaceResolutionApi() throws Exception { IProject[] projects = importProjects( "projects/simple-pom", new String[] {"pom.xml"}, new ResolverConfiguration()); assertEquals(1, projects.length); assertNotNull(projects[0]); Artifact artifact = new DefaultArtifact( "org.eclipse.m2e.projects", "simple-pom", "1.0.0", null, "pom", "", null); artifact = manager.getWorkspaceLocalRepository().find(artifact); assertTrue(artifact.isResolved()); assertNotNull(artifact.getFile()); assertEquals(projects[0].getFile("pom.xml").getLocation().toFile(), artifact.getFile()); }
public void testUnpackOverWriteIfNewer() throws Exception { final long now = System.currentTimeMillis(); setSilent(mojo, false); stubFactory.setCreateFiles(true); Artifact artifact = stubFactory.getSnapshotArtifact(); assertTrue(artifact.getFile().setLastModified(now - 20000)); ArtifactItem item = new ArtifactItem(artifact); List<ArtifactItem> list = Collections.singletonList(item); mojo.setArtifactItems(list); mojo.setOverWriteIfNewer(true); mojo.execute(); File unpackedFile = getUnpackedFile(item); // round down to the last second long time = now; time = time - (time % 1000); // go back 10 more seconds for linux time -= 10000; // set to known value assertTrue(unpackedFile.setLastModified(time)); // set source to be newer was 4s but test is brittle on MacOS if less than 5s assertTrue(artifact.getFile().setLastModified(time + 5000)); // manually set markerfile (must match getMarkerFile in DefaultMarkerFileHandler) File marker = new File(mojo.getMarkersDirectory(), artifact.getId().replace(':', '-') + ".marker"); assertTrue(marker.setLastModified(time)); displayFile("unpackedFile", unpackedFile); displayFile("artifact ", artifact.getFile()); displayFile("marker ", marker); System.out.println("mojo.execute()"); mojo.execute(); displayFile("unpackedFile", unpackedFile); displayFile("artifact ", artifact.getFile()); displayFile("marker ", marker); System.out.println("marker.lastModified() = " + marker.lastModified()); System.out.println("unpackedFile.lastModified() = " + unpackedFile.lastModified()); assertTrue( "unpackedFile '" + unpackedFile + "' lastModified() == " + marker.lastModified() + ": should be different", marker.lastModified() != unpackedFile.lastModified()); }
/** * Returns the fully qualified path to an war file in the artifact list. * * @param inArtifacts - the set of artifacts * @param fileName - the file name we are looking for in the aftifact list * @return the fully qualified path to an war file in the artifact list. */ public static File getWarFileName(final Set inArtifacts, String fileName) { if (inArtifacts == null || inArtifacts.isEmpty()) { throw new IllegalArgumentException("WAR not found in artifact list."); } final Iterator iter = inArtifacts.iterator(); while (iter.hasNext()) { Artifact artifact = (Artifact) iter.next(); if ("war".equals(artifact.getType()) && artifact.getFile().getName().contains(fileName)) { return artifact.getFile(); } } throw new IllegalArgumentException("WAR not found in artifact list."); }
/** * Add any relevant project dependencies to the classpath. Indirectly takes * includePluginDependencies and ExecutableDependency into consideration. * * @param path classpath of {@link java.net.URL} objects * @throws MojoExecutionException */ private void addExtraPluginDependenciesToClasspath(Set<URL> path) throws MojoExecutionException { if (extraPluginDependencyArtifactId == null) { return; } try { Set<Artifact> artifacts = new HashSet<Artifact>(this.pluginDependencies); for (Artifact artifact : artifacts) { // must if (artifact.getArtifactId().equals(extraPluginDependencyArtifactId)) { getLog() .debug( "Adding extra plugin dependency artifact: " + artifact.getArtifactId() + " to classpath"); path.add(artifact.getFile().toURI().toURL()); // add the transient dependencies of this artifact Set<Artifact> deps = resolveExecutableDependencies(artifact); for (Artifact dep : deps) { // we must skip org.apache.aries.blueprint.core:, otherwise we get duplicate blueprint // extenders if (dep.getArtifactId().equals("org.apache.aries.blueprint.core")) { getLog() .debug( "Skipping org.apache.aries.blueprint.core -> " + dep.getGroupId() + "/" + dep.getArtifactId() + "/" + dep.getVersion()); continue; } getLog() .debug( "Adding extra plugin dependency artifact: " + dep.getArtifactId() + " to classpath"); path.add(dep.getFile().toURI().toURL()); } } } } catch (MalformedURLException e) { throw new MojoExecutionException("Error during setting up classpath", e); } }
private void packageBundle() throws Exception { File jar = null; File outputDirectory = new File(project.getBuild().getOutputDirectory()); if (projectJar != null && outputDirectory.exists()) { JarArchiver jarer = (JarArchiver) plexus.lookup(JarArchiver.ROLE, "jar"); jar = new File(project.getBasedir(), jars + "/" + projectJar); jarer.setDestFile(jar); jarer.addDirectory(outputDirectory); jarer.createArchive(); } // what is the right way of doing this? File file; // if (PACKAGING_DIRECTORY_PLUGIN.equals(project.getPackaging())) { file = new File(buildTarget, project.getBuild().getFinalName() + ".jar"); // } else { // file = new File(buildTarget, project.getArtifact().getArtifactId() + "-" + // project.getArtifact().getVersion()); // } JarArchiver archiver = (JarArchiver) plexus.lookup(JarArchiver.ROLE, "jar"); archiver.setDestFile(file); File mfile = expandVersion(new File(project.getBasedir(), "META-INF/MANIFEST.MF")); archiver.setManifest(mfile); if (jar != null) { archiver.addFile(jar, jars + "/" + jar.getName()); } for (Iterator i = getIncludedArtifacts().iterator(); i.hasNext(); ) { Artifact d = (Artifact) i.next(); archiver.addFile(d.getFile(), jars + "/" + d.getFile().getName()); } if (bundleClasspath != null) { for (int i = 0; i < bundleClasspath.length; i++) { archiver.addFile(new File(project.getBasedir(), bundleClasspath[i]), bundleClasspath[i]); } } archiver.createArchive(); // if (PACKAGING_DIRECTORY_PLUGIN.equals(project.getArtifact().getType())) { project.getArtifact().setFile(file); // } else { // projectHelper.attachArtifact(project, TYPE_DIRECTORY_PLUGIN, // CLASSIFIER_DIRECTORY_PLUGIN, file); // } }
/** * Log Projects and their resolved dependencies via MavenProject.getArtifacts(). * * @param reactorProjects MavenProjects in the current reactor */ private void checkReactor(final List<MavenProject> reactorProjects) { for (final MavenProject reactorProject : reactorProjects) { final String msg = "Check resolved Artifacts for: " + "\ngroudId: " + reactorProject.getGroupId() + "\nartifactId: " + reactorProject.getArtifactId() + "\nversion: " + reactorProject.getVersion(); if (getLog().isDebugEnabled()) getLog().debug(msg); if (reactorProject.getArtifacts() == null || reactorProject.getArtifacts().isEmpty()) { if (getLog().isDebugEnabled()) getLog().debug("+ Dependencies not resolved or Reactor-Project has no dependencies!"); } else { for (final Artifact artifact : reactorProject.getArtifacts()) { if (getLog().isDebugEnabled()) getLog() .debug( " + " + artifact.getGroupId() + " : " + artifact.getArtifactId() + " : " + artifact.getVersion() + " : " + artifact.getType() + " : " + artifact.getFile()); } } } }
protected File getFile(String artifactName) { // artifactMap is a bit too simplistic for (Artifact artifact : project.getArtifacts()) if (artifact.toString().startsWith(artifactName)) return artifact.getFile(); throw new IllegalArgumentException( "could not find " + artifactName + " in " + project.getArtifacts()); }
/** * Creates a string containing the classpath for running this Cassandra node as a CassandraDaemon * in a separate JVM process. * * <p>Uses the dependencies for the plugin to form the classpath, since the plugin is dependent * upon Cassandra. * * @return the classpath, as a colon-separated String. */ private String getClasspath() { // Copied mostly from the Codehaus Cassandra plugin. StringBuilder cp = new StringBuilder(); try { // We can't use StringUtils.join here since we need to add a '/' to // the end of directory entries - otherwise the jvm will ignore them. cp.append(new URL(mConfDir.toURI().toASCIIString()).toExternalForm()); cp.append(CLASSPATH_SEPARATOR); for (Artifact artifact : mCassandraConfiguration.getPluginDependencies()) { getLog() .debug( "Adding plugin dependency artifact: " + ArtifactUtils.versionlessKey(artifact) + " to the classpath"); // NOTE: if File points to a directory, this entry MUST end in '/'. cp.append(new URL(artifact.getFile().toURI().toASCIIString()).toExternalForm()); cp.append(CLASSPATH_SEPARATOR); } } catch (MalformedURLException mue) { getLog().error("Could not create URL for conf dir " + mConfDir + "?!"); } return cp.toString(); }
static String getDependenciesText(AbstractJnlpMojo config) { String dependenciesText = ""; List artifacts = config.getPackagedJnlpArtifacts(); if (artifacts.size() != 0) { StringBuffer buffer = new StringBuffer(100 * artifacts.size()); buffer.append("\n"); String jarLibPath = null; if (config.getLibPath() != null) { jarLibPath = config.getLibPath(); jarLibPath = (jarLibPath != null && jarLibPath.trim().length() != 0) ? jarLibPath.trim() : null; } for (int i = 0; i < artifacts.size(); i++) { Artifact artifact = (Artifact) artifacts.get(i); buffer.append("<jar href=\""); if (jarLibPath != null) { buffer.append(jarLibPath).append("/"); } buffer.append(artifact.getFile().getName()).append("\""); if (config.isOutputJarVersions()) { buffer.append(" version=\"").append(artifact.getVersion()).append("\""); } if (config.isArtifactWithMainClass(artifact)) { buffer.append(" main=\"true\""); } buffer.append("/>\n"); } dependenciesText = buffer.toString(); } return dependenciesText; }
public void execute() throws MojoExecutionException { try { File out = new File(project.getBasedir(), jars); for (Iterator i = getIncludedArtifacts().iterator(); i.hasNext(); ) { Artifact a = (Artifact) i.next(); FileUtils.copyFileToDirectory(a.getFile(), out); } if (packageSources) { packageSources(getIncludedArtifacts()); } Manifest manifest = getManifest(); File metaInf = new File(project.getBasedir(), "META-INF"); metaInf.mkdirs(); BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(new File(metaInf, "MANIFEST.MF"))); manifest.write(os); os.close(); // packageBundle(); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }
protected void downloadRemoteDocs(List<WadlOption> effectiveOptions) throws MojoExecutionException { List<?> remoteRepos; try { remoteRepos = ProjectUtils.buildArtifactRepositories( repositories, artifactRepositoryFactory, mavenSession.getContainer()); } catch (InvalidRepositoryException e) { throw new MojoExecutionException("Error build repositories for remote wsdls", e); } for (WadlOption option : effectiveOptions) { DocumentArtifact wsdlA = option.getWadlArtifact(); if (wsdlA == null) { return; } Artifact wsdlArtifact = artifactFactory.createArtifact( wsdlA.getGroupId(), wsdlA.getArtifactId(), wsdlA.getVersion(), Artifact.SCOPE_COMPILE, wsdlA.getType()); wsdlArtifact = resolveRemoteWsdlArtifact(remoteRepos, wsdlArtifact); if (wsdlArtifact != null) { String path = wsdlArtifact.getFile().getAbsolutePath(); getLog().info("Resolved WSDL artifact to file " + path); option.setWadl(path); } } }