private void addArtifactPath(Artifact a, List list) throws DependencyResolutionRequiredException { File file = a.getFile(); if ( file == null ) { throw new DependencyResolutionRequiredException( a ); } list.add( file.getPath() ); }
public static URLClassLoader getUrlClassLoader(MavenProject project) throws MojoFailureException { try { // collect compile classpath classes URL[] urls = project.getCompileClasspathElements().stream() .map(File::new) .filter(File::exists) .map(new FileToUrl()).toArray(URL[]::new); return new URLClassLoader(urls, currentThread().getContextClassLoader()); } catch (DependencyResolutionRequiredException e) { throw new MojoFailureException(e.getMessage(), e); } }
/** * Get compile elements (i.e., classes under /target/classes) * * @param project * @return */ public static List<String> getCompileClasspathElements(MavenProject project) { List<String> compileClassPath = new ArrayList<String>(); try { project.getCompileClasspathElements() .stream() // we only target what has been compiled to a folder .filter(element -> !element.endsWith(".jar")) .filter(element -> new File(element).exists()) .forEach(element -> compileClassPath.add(element)); } catch (DependencyResolutionRequiredException e) { e.printStackTrace(); } return compileClassPath; }
/** Replies the classpath for the standard code. * * @return the current classpath. * @throws MojoExecutionException on failure. * @see #getTestClassPath() */ protected List<File> getClassPath() throws MojoExecutionException { final Set<String> classPath = new LinkedHashSet<>(); final MavenProject project = getProject(); classPath.add(project.getBuild().getSourceDirectory()); try { classPath.addAll(project.getCompileClasspathElements()); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } for (final Artifact dep : project.getArtifacts()) { classPath.add(dep.getFile().getAbsolutePath()); } classPath.remove(project.getBuild().getOutputDirectory()); final List<File> files = new ArrayList<>(); for (final String filename : classPath) { final File file = new File(filename); if (file.exists()) { files.add(file); } else { getLog().warn(MessageFormat.format(Messages.AbstractSarlBatchCompilerMojo_10, filename)); } } return files; }
protected ClassLoader getProjectClassLoader() throws MojoFailureException { final List<?> classpathElements; try { classpathElements = project.getTestClasspathElements(); } catch (org.apache.maven.artifact.DependencyResolutionRequiredException e) { throw new MojoFailureException(e.getMessage(), e); } final URL[] urls = new URL[classpathElements.size()]; int i = 0; for (Iterator<?> it = classpathElements.iterator(); it.hasNext(); i++) { try { urls[i] = new File((String) it.next()).toURI().toURL(); } catch (MalformedURLException e) { throw new MojoFailureException(e.getMessage(), e); } } final ClassLoader tccl = Thread.currentThread().getContextClassLoader(); return new URLClassLoader(urls, tccl != null ? tccl : getClass().getClassLoader()); }
/** * Get runtime elements * * @param project * @return */ public static List<String> getRuntimeClasspathElements(MavenProject project) { List<String> runtimeClassPath = new ArrayList<String>(); try { project.getRuntimeClasspathElements() .stream() .filter(element -> new File(element).exists()) .forEach(element -> runtimeClassPath.add(element)); } catch (DependencyResolutionRequiredException e) { e.printStackTrace(); } return runtimeClassPath; }
/** Replies the current classpath. * * @return the current classpath. * @throws IOException on failure. */ protected List<File> getClassPath() throws IOException { final Set<String> classPath = new LinkedHashSet<>(); classPath.add(this.session.getCurrentProject().getBuild().getSourceDirectory()); try { classPath.addAll(this.session.getCurrentProject().getCompileClasspathElements()); } catch (DependencyResolutionRequiredException e) { throw new IOException(e.getLocalizedMessage(), e); } for (final Artifact dep : this.session.getCurrentProject().getArtifacts()) { classPath.add(dep.getFile().getAbsolutePath()); } classPath.remove(this.session.getCurrentProject().getBuild().getOutputDirectory()); final List<File> files = new ArrayList<>(); for (final String filename : classPath) { final File file = new File(filename); if (file.exists()) { files.add(file); } } return files; }
/** * Executes the WarMojo on the current project. * * @throws MojoExecutionException if an error occurred while building the webapp */ public void execute() throws MojoExecutionException { try { performPackaging(); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Error assembling hpi: " + e.getMessage(), e); } catch (ManifestException e) { throw new MojoExecutionException("Error assembling hpi", e); } catch (IOException e) { throw new MojoExecutionException("Error assembling hpi", e); } catch (ArchiverException e) { throw new MojoExecutionException("Error assembling hpi: " + e.getMessage(), e); } }
public List getTestClasspathElements() throws DependencyResolutionRequiredException { List list = new ArrayList( getArtifacts().size() + 1 ); list.add( getBuild().getTestOutputDirectory() ); list.add( getBuild().getOutputDirectory() ); for ( Iterator i = getArtifacts().iterator(); i.hasNext(); ) { Artifact a = (Artifact) i.next(); if ( a.getArtifactHandler().isAddedToClasspath() ) { // TODO: let the scope handler deal with this // NOTE: [jc] scope == 'test' is the widest possible scope, so we don't really need to perform // this check... // if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() ) || // Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) // { // } File file = a.getFile(); if ( file == null ) { throw new DependencyResolutionRequiredException( a ); } list.add( file.getPath() ); } } return list; }
/** * Get JUnit elements (i.e., classes under /target/test-classes) and compiled * elements (i.e., classes under /target/classes) * * @param project * @return */ public static List<String> getTestClasspathElements(MavenProject project) { List<String> testClassPath = new ArrayList<String>(); try { project.getTestClasspathElements() .stream() // we only target what has been compiled to a folder .filter(element -> !element.endsWith(".jar")) .filter(element -> new File(element).exists()) .forEach(element -> testClassPath.add(element)); } catch (DependencyResolutionRequiredException e) { e.printStackTrace(); } return testClassPath; }
/** Replies the classpath for the test code. * * @return the current classpath. * @throws MojoExecutionException on failure. * @since 0.8 * @see #getClassPath() */ protected List<File> getTestClassPath() throws MojoExecutionException { final Set<String> classPath = new LinkedHashSet<>(); final MavenProject project = getProject(); classPath.add(project.getBuild().getTestSourceDirectory()); try { classPath.addAll(project.getTestClasspathElements()); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } for (final Artifact dep : project.getArtifacts()) { classPath.add(dep.getFile().getAbsolutePath()); } final List<File> files = new ArrayList<>(); for (final String filename : classPath) { final File file = new File(filename); if (file.exists()) { files.add(file); } else { getLog().warn(MessageFormat.format(Messages.AbstractSarlBatchCompilerMojo_10, filename)); } } return files; }
/** * Executes the JarMojo on the current project. * * @throws MojoExecutionException if an error occurred while building the webapp */ public void execute() throws MojoExecutionException { try { performPackaging(); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Error assembling jar: " + e.getMessage(), e); } catch (ManifestException e) { throw new MojoExecutionException("Error assembling jar", e); } catch (IOException e) { throw new MojoExecutionException("Error assembling jar", e); } catch (ArchiverException e) { throw new MojoExecutionException("Error assembling jar: " + e.getMessage(), e); } }
public List getRuntimeClasspathElements() throws DependencyResolutionRequiredException { List list = new ArrayList( getArtifacts().size() + 1 ); list.add( getBuild().getOutputDirectory() ); for ( Iterator i = getArtifacts().iterator(); i.hasNext(); ) { Artifact a = (Artifact) i.next(); if ( a.getArtifactHandler().isAddedToClasspath() ) { // TODO: let the scope handler deal with this if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) { File file = a.getFile(); if ( file == null ) { throw new DependencyResolutionRequiredException( a ); } list.add( file.getPath() ); } } } return list; }
URI[] createPath() { List lst = new ArrayList(); MavenProject prj = getMavenProject().getOriginalMavenProject(); if (prj != null && prj.getBuild() != null) { File fil = new File(prj.getBuild().getOutputDirectory()); fil = FileUtil.normalizeFile(fil); lst.add(fil.toURI()); } try { List srcs = getMavenProject().getOriginalMavenProject().getRuntimeClasspathElements(); Iterator it = srcs.iterator(); while (it.hasNext()) { String str = (String)it.next(); File fil = FileUtil.normalizeFile(new File(str)); lst.add(fil.toURI()); } } catch (DependencyResolutionRequiredException ex) { ex.printStackTrace(); } URI[] uris = new URI[lst.size()]; uris = (URI[])lst.toArray(uris); return uris; }
throw new MojoExecutionException( "DependencyResolutionRequiredException: " + e.getMessage(), e );
public Path getPathFromArtifacts( Collection<Artifact> artifacts, Project antProject ) throws DependencyResolutionRequiredException { List<String> list = new ArrayList<>( artifacts.size() ); for ( Artifact a : artifacts ) { File file = a.getFile(); if ( file == null ) { throw new DependencyResolutionRequiredException( a ); } list.add( file.getPath() ); } Path p = new Path( antProject ); p.setPath( StringUtils.join( list.iterator(), File.pathSeparator ) ); return p; }
cp = convertToSourcePath(roots); } catch (DependencyResolutionRequiredException ex) { ex.printStackTrace(); cp = ClassPathSupport.createClassPath(new FileObject[0]);
/** * @return URLs for the classpath with compile scope needed jars */ protected List<URL> getDependencyArtifactUrls() { final List<URL> urlList = new ArrayList<>(); final List<String> compileClasspathElements = new ArrayList<>(); try { compileClasspathElements.addAll(this.getProject().getCompileClasspathElements()); } catch (DependencyResolutionRequiredException e) { debug("Failed to resolve dependencies for compile scope, exception: " + e.getMessage()); } for (final String element : compileClasspathElements) { final File f = new File(element); try { urlList.add(f.toURI().toURL()); } catch (MalformedURLException e) { debug("Failed to get URL for file: " + f.toString()); } } return urlList; }
public Path getPathFromArtifacts( Collection artifacts, Project antProject ) throws DependencyResolutionRequiredException { List list = new ArrayList( artifacts.size() ); for ( Iterator i = artifacts.iterator(); i.hasNext(); ) { Artifact a = (Artifact) i.next(); File file = a.getFile(); if ( file == null ) { throw new DependencyResolutionRequiredException( a ); } list.add( file.getPath() ); } Path p = new Path( antProject ); p.setPath( StringUtils.join( list.iterator(), File.pathSeparator ) ); return p; }
public void execute() throws MojoExecutionException, MojoFailureException { try { getLog().info( "Building archetype jar: " + new File( outputDirectory, finalName ) ); File jarFile = manager.archiveArchetype( archetypeDirectory, outputDirectory, finalName ); checkArchetypeFile( jarFile ); project.getArtifact().setFile( jarFile ); } catch ( DependencyResolutionRequiredException ex ) { throw new MojoExecutionException( ex.getMessage(), ex ); } catch ( IOException ex ) { throw new MojoExecutionException( ex.getMessage(), ex ); } }