use of org.apache.maven.artifact.DependencyResolutionRequiredException in project compss by bsc-wdc.
the class InstrumentMojo method execute.
public void execute() throws MojoExecutionException {
try {
getLog().info("COMPSs code instrumentation...");
if (outputDirectory != null && outputDirectory.exists() && project != null) {
String classesFolder = outputDirectory.getAbsolutePath().concat(File.separator + "classes");
getLog().debug("Classes folder " + classesFolder);
List<String> ccp = project.getCompileClasspathElements();
List<String> cp = project.getRuntimeClasspathElements();
cp.addAll(ccp);
if (metadataFile != null && metadataFile.exists()) {
getLog().info("Getting values from metadata file...");
ProjectMetadata prMeta = new ProjectMetadata(metadataFile);
String[] extClasses = prMeta.getExternalOrchestrationClasses();
compssLocation = prMeta.getRuntimeLocation();
for (String cl : extClasses) {
getLog().warn("External classses not supported yet, skipping cl");
// extractPackages
// String classesFolder = addOrchestration(cp, cl, prMeta.getOrchestrationElementFormExternalClass(cl));
// instrument(cp, classesFolder, cl);
}
String[] intClasses = prMeta.getNonExternalOrchestrationClasses();
CommonUtils.instrumentOrchestrations(compssLocation, intClasses, classesFolder, cp, prMeta.getOrchestrationClassesTypes(intClasses), mainClass);
} else {
getLog().info("Metadata does not exists.");
}
if (orchestrations != null && orchestrations.length > 0) {
getLog().info("Treating defined orchestrations ...");
Map<String, List<String>> orchClassAndElements = ElementLabelUtils.getClassesAndElements(orchestrations);
for (Entry<String, List<String>> entry : orchClassAndElements.entrySet()) {
CommonUtils.preInstrumentOrchestration(compssLocation, entry.getKey(), entry.getValue(), classesFolder, cp);
String cl = entry.getKey();
boolean isWs = webServiceClasses != null && webServiceClasses.contains(cl) ? true : false;
boolean isMainClass = mainClass != null && cl.equals(mainClass) ? true : false;
CommonUtils.instrumentOrchestration(compssLocation, cl, classesFolder, cp, isWs, isMainClass);
}
} else {
getLog().info("There are not defined orchestrations.");
}
} else {
getLog().error("Output dir " + outputDirectory.getAbsolutePath() + " or maven project does not exist");
throw new MojoExecutionException("Output dir or maven project does not exist");
}
} catch (DependencyResolutionRequiredException e) {
getLog().error("Exception getting project classpath");
getLog().error(e);
throw new MojoExecutionException("Exception getting project classpath", e);
} catch (SAXException e) {
getLog().error("Exception parsing metadata file");
getLog().error(e);
throw new MojoExecutionException("Exception parsing metadata file", e);
} catch (IOException e) {
getLog().error("Exception parsing metadata file");
getLog().error(e);
throw new MojoExecutionException("Exception parsing metadata file", e);
} catch (ParserConfigurationException e) {
getLog().error("Exception parsing metadata file");
getLog().error(e);
throw new MojoExecutionException("Exception parsing metadata file", e);
} catch (Exception e) {
getLog().error("Exception getting orchestration Classes");
getLog().error(e);
throw new MojoExecutionException("Exception getting orchestration Classes", e);
}
}
use of org.apache.maven.artifact.DependencyResolutionRequiredException in project scala-maven-plugin by davidB.
the class ScalaDocJarMojo method generateArchive.
/**
* Method that creates the jar file
*
* @param javadocFiles the directory where the generated jar file will be put
* @param jarFileName the filename of the generated jar file
* @return a File object that contains the generated jar file
* @throws ArchiverException
* @throws IOException
*/
private File generateArchive(File javadocFiles, String jarFileName) throws ArchiverException, IOException {
final File javadocJar = new File(jarOutputDirectory, jarFileName);
if (javadocJar.exists()) {
javadocJar.delete();
}
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(javadocJar);
File contentDirectory = javadocFiles;
if (!contentDirectory.exists()) {
getLog().warn("JAR will be empty - no content was marked for inclusion!");
} else {
archiver.getArchiver().addDirectory(contentDirectory, DEFAULT_INCLUDES, DEFAULT_EXCLUDES);
}
List<Resource> resources = project.getBuild().getResources();
for (Resource r : resources) {
if (r.getDirectory().endsWith("maven-shared-archive-resources")) {
archiver.getArchiver().addDirectory(new File(r.getDirectory()));
}
}
if (useDefaultManifestFile && defaultManifestFile.exists() && archive.getManifestFile() == null) {
getLog().info("Adding existing MANIFEST to archive. Found under: " + defaultManifestFile.getPath());
archive.setManifestFile(defaultManifestFile);
}
try {
// we don't want Maven stuff
archive.setAddMavenDescriptor(false);
archiver.createArchive(project, archive);
} catch (ManifestException e) {
throw new ArchiverException("ManifestException: " + e.getMessage(), e);
} catch (DependencyResolutionRequiredException e) {
throw new ArchiverException("DependencyResolutionRequiredException: " + e.getMessage(), e);
}
return javadocJar;
}
use of org.apache.maven.artifact.DependencyResolutionRequiredException in project microservice_framework by CJSCommonPlatform.
the class HandlerScanner method getHandlesActions.
public Collection<String> getHandlesActions(final MavenProject project) throws LintCheckPluginException {
final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
final Set<URL> urls = new HashSet<>();
for (String element : project.getRuntimeClasspathElements()) {
urls.add(new File(element).toURI().toURL());
}
final ClassLoader contextClassLoader = URLClassLoader.newInstance(urls.toArray(new URL[0]), originalClassLoader);
Thread.currentThread().setContextClassLoader(contextClassLoader);
} catch (DependencyResolutionRequiredException | MalformedURLException e) {
throw new LintCheckPluginException("Could not set up class loader", e);
}
final List<String> actions = scanForActions(configureReflections());
Thread.currentThread().setContextClassLoader(originalClassLoader);
return actions;
}
use of org.apache.maven.artifact.DependencyResolutionRequiredException in project narayana by jbosstm.
the class LraCheckerMavenPlugin method providePathsToClassLoader.
private ClassLoader providePathsToClassLoader(String[] pathsToBeClassLoaded) throws MojoFailureException {
URLClassLoader classLoader = null;
String currentPathProcessed = null;
try {
// classes which are expected to be scanned by Weld extension
List<URL> pathUrls = new ArrayList<>();
for (String paramPath : pathsToBeClassLoaded) {
currentPathProcessed = paramPath;
pathUrls.add(new File(paramPath).toURI().toURL());
}
// adding compile classpath as expected to be needed for Weld can initiate the classes for evaluation
for (String mavenCompilePath : project.getCompileClasspathElements()) {
currentPathProcessed = mavenCompilePath;
pathUrls.add(new File(mavenCompilePath).toURI().toURL());
}
URL[] urlsForClassLoader = pathUrls.toArray(new URL[pathUrls.size()]);
getLog().debug("urls for URLClassLoader: " + Arrays.asList(urlsForClassLoader));
// need to define parent classloader which knows all dependencies of the plugin (e.g. LRA annotations)
classLoader = new URLClassLoader(urlsForClassLoader, LraCheckerMavenPlugin.class.getClassLoader());
} catch (MalformedURLException | DependencyResolutionRequiredException e) {
throw new MojoFailureException("Failed to processed '" + currentPathProcessed + "' for the URLClassLoader", e);
}
return classLoader;
}
use of org.apache.maven.artifact.DependencyResolutionRequiredException in project evosuite by EvoSuite.
the class GenerateMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Going to generate tests with EvoSuite");
getLog().info("Total memory: " + memoryInMB + "mb");
getLog().info("Time per class: " + timeInMinutesPerClass + " minutes");
getLog().info("Number of used cores: " + numberOfCores);
if (cuts != null) {
getLog().info("Specified classes under test: " + cuts);
}
String target = null;
String cp = null;
try {
// the targets we want to generate tests for, ie the CUTs
for (String element : project.getCompileClasspathElements()) {
if (element.endsWith(".jar")) {
// we only target what has been compiled to a folder
continue;
}
File file = new File(element);
if (!file.exists()) {
/*
* don't add to target an element that does not exist
*/
continue;
}
if (!file.getAbsolutePath().startsWith(project.getBasedir().getAbsolutePath())) {
/*
This can happen in multi-module projects when module A has dependency on
module B. Then, both A and B source folders will end up on compile classpath,
although we are interested only in A
*/
continue;
}
if (target == null) {
target = element;
} else {
target = target + File.pathSeparator + element;
}
}
// build the classpath
Set<String> alreadyAdded = new HashSet<>();
for (String element : project.getTestClasspathElements()) {
if (element.toLowerCase().contains("powermock")) {
// PowerMock just leads to a lot of troubles, as it includes tools.jar code
getLog().warn("Skipping PowerMock dependency at: " + element);
continue;
}
if (element.toLowerCase().contains("jmockit")) {
// JMockit has same issue
getLog().warn("Skipping JMockit dependency at: " + element);
continue;
}
getLog().debug("TEST ELEMENT: " + element);
cp = addPathIfExists(cp, element, alreadyAdded);
}
} catch (DependencyResolutionRequiredException e) {
getLog().error("Error: " + e.getMessage(), e);
return;
}
File basedir = project.getBasedir();
getLog().info("Target: " + target);
getLog().debug("Classpath: " + cp);
getLog().info("Basedir: " + basedir.getAbsolutePath());
if (target == null || cp == null || basedir == null) {
getLog().info("Nothing to test");
return;
}
runEvoSuiteOnSeparatedProcess(target, cp, basedir.getAbsolutePath());
}
Aggregations