List of usage examples for org.apache.maven.plugin.logging Log debug
void debug(Throwable error);
From source file:org.apache.tuscany.maven.bundle.plugin.ThirdPartyBundleBuildMojo.java
License:Apache License
public void execute() throws MojoExecutionException { Log log = getLog(); String projectGroupId = project.getGroupId(); Set<File> jarFiles = new HashSet<File>(); for (Object o : project.getArtifacts()) { Artifact artifact = (Artifact) o; if (!(Artifact.SCOPE_COMPILE.equals(artifact.getScope()) || Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) { if (log.isDebugEnabled()) { log.debug("Skipping artifact: " + artifact); }//from www. ja v a2 s .c o m continue; } if (!"jar".equals(artifact.getType())) { continue; } if (projectGroupId.equals(artifact.getGroupId())) { continue; } if (log.isDebugEnabled()) { log.debug("Artifact: " + artifact); } String bundleName = null; try { bundleName = BundleUtil.getBundleSymbolicName(artifact.getFile()); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } if (bundleName == null || true) { if (artifact.getFile().exists()) { log.info("Adding third party jar: " + artifact); jarFiles.add(artifact.getFile()); } else { log.warn("Third party jar not found: " + artifact); } } } try { String version = BundleUtil.osgiVersion(project.getVersion()); Manifest mf = BundleUtil.libraryManifest(jarFiles, project.getName(), symbolicName, version, "lib"); File file = new File(project.getBasedir(), "META-INF"); file.mkdir(); file = new File(file, "MANIFEST.MF"); if (log.isDebugEnabled()) { log.debug("Generating " + file); } FileOutputStream fos = new FileOutputStream(file); write(mf, fos); fos.close(); File lib = new File(project.getBasedir(), "lib"); if (lib.isDirectory()) { for (File c : lib.listFiles()) { c.delete(); } } lib.mkdir(); byte[] buf = new byte[4096]; for (File jar : jarFiles) { File jarFile = new File(lib, jar.getName()); if (log.isDebugEnabled()) { log.debug("Copying " + jar + " to " + jarFile); } FileInputStream in = new FileInputStream(jar); FileOutputStream out = new FileOutputStream(jarFile); for (;;) { int len = in.read(buf); if (len > 0) { out.write(buf, 0, len); } else { break; } } in.close(); out.close(); } } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:org.apache.tuscany.maven.plugin.surefire.OSGiSurefirePlugin.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { if (project.getPackaging().equals("pom")) { return;/*from w ww . j a v a2s . c om*/ } if (verifyParameters()) { OSGiSurefireBooter surefireBooter = constructSurefireBooter(); Log log = getLog(); Set<String> jarFiles = new HashSet<String>(); /* for (Object o : project.getArtifacts()) { Artifact a = (Artifact)o; if ("pom".equals(a.getType())) { // Skip pom projects continue; } try { if (log.isDebugEnabled()) { log.debug("Adding: " + a); } jarFiles.add(a.getFile().toURI().toURL()); } catch (MalformedURLException e) { getLog().error(e); } } */ /* * Add org.apache.tuscany.sca:tuscany-extensibility-osgi module */ Artifact ext = getArtifact("org.apache.tuscany.sca", "tuscany-extensibility-equinox"); if (log.isDebugEnabled()) { log.debug("Adding: " + ext); } jarFiles.add(ext.getFile().getAbsolutePath()); Artifact con = getArtifact("org.apache.tuscany.sca", "tuscany-contribution-osgi"); if (log.isDebugEnabled()) { log.debug("Adding: " + con); } jarFiles.add(con.getFile().getAbsolutePath()); String name = project.getBuild().getFinalName(); String mainBundleName = null; File mainJar = new File(project.getBuild().getDirectory(), name + "-osgi.jar"); File testJar = new File(project.getBuild().getDirectory(), name + "-osgi-tests.jar"); try { Manifest manifest = createMainBundle(); mainBundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); int sc = mainBundleName.indexOf(';'); if (sc != -1) { mainBundleName = mainBundleName.substring(0, sc); } generateJar(classesDirectory, mainJar, manifest); Manifest testManifest = createTestFragment(manifest); generateJar(testClassesDirectory, testJar, testManifest); jarFiles.add(mainJar.getAbsolutePath()); jarFiles.add(testJar.getAbsolutePath()); } catch (IOException e) { getLog().error(e); } if (log.isDebugEnabled()) { log.debug("Main bundle: " + mainBundleName); } surefireBooter.setMainBundleName(mainBundleName); for (String url : jarFiles) { surefireBooter.addClassPathUrl(url); } getLog().info("Surefire report directory: " + reportsDirectory); int result; try { result = surefireBooter.run(); } catch (SurefireBooterForkException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (SurefireExecutionException e) { throw new MojoExecutionException(e.getMessage(), e); } if (originalSystemProperties != null && !surefireBooter.isForking()) { // restore system properties, only makes sense when not forking.. System.setProperties(originalSystemProperties); } if (result == 0) return; String msg; if (result == OSGiSurefireBooter.NO_TESTS_EXIT_CODE) { if ((failIfNoTests == null) || !failIfNoTests.booleanValue()) return; // TODO: i18n throw new MojoFailureException( "No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)"); } else { // TODO: i18n msg = "There are test failures.\n\nPlease refer to " + reportsDirectory + " for the individual test results."; } if (testFailureIgnore) { getLog().error(msg); } else { throw new MojoFailureException(msg); } } }
From source file:org.arakhne.maven.ExtendedArtifact.java
License:Open Source License
/** Replies the people with the given login. * This function checks the peoples replied * by {@link #getDevelopers()} and/* w w w . j a v a 2 s . c om*/ * {@link #getContributors()}. * * @param login * @param logger * @return the people or <code>null</code> */ public Contributor getPeople(String login, Log logger) { for (Developer devel : getDevelopers()) { if (devel != null) { if (logger != null && logger.isDebugEnabled()) { logger.debug("Comparing '" + login //$NON-NLS-1$ + " to the developer [ID=" + devel.getId() //$NON-NLS-1$ + ";NAME=" + devel.getName() //$NON-NLS-1$ + ";EMAIL=" + devel.getEmail() //$NON-NLS-1$ + "]"); //$NON-NLS-1$ } String idprop = null; Properties props = devel.getProperties(); if (props != null) { idprop = props.getProperty("id", null); //$NON-NLS-1$ if (idprop == null) idprop = props.getProperty("login", null); //$NON-NLS-1$ } if (login.equals(devel.getId()) || login.equals(devel.getName()) || login.equals(devel.getEmail()) || login.equals(idprop)) { if (logger != null && logger.isDebugEnabled()) { logger.debug("Selecting the developer [ID=" + devel.getId() //$NON-NLS-1$ + ";NAME=" + devel.getName() //$NON-NLS-1$ + ";EMAIL=" + devel.getEmail() //$NON-NLS-1$ + "]"); //$NON-NLS-1$ } return devel; } } } for (Contributor contrib : getContributors()) { if (contrib != null) { if (logger != null && logger.isDebugEnabled()) { logger.debug("Comparing '" + login //$NON-NLS-1$ + " to the contributor [NAME=" + contrib.getName() //$NON-NLS-1$ + ";EMAIL=" + contrib.getEmail() //$NON-NLS-1$ + "]"); //$NON-NLS-1$ } String idprop = null; Properties props = contrib.getProperties(); if (props != null) { idprop = props.getProperty("id", null); //$NON-NLS-1$ if (idprop == null) idprop = props.getProperty("login", null); //$NON-NLS-1$ } if (login.equals(contrib.getName()) || login.equals(contrib.getEmail()) || login.equals(idprop)) { if (logger != null && logger.isDebugEnabled()) { logger.debug("Selecting the contributor [NAME=" + contrib.getName() //$NON-NLS-1$ + ";EMAIL=" + contrib.getEmail() //$NON-NLS-1$ + "]"); //$NON-NLS-1$ } return contrib; } } } if (logger != null && logger.isDebugEnabled()) { logger.debug("No people found for: " + login); //$NON-NLS-1$ logger.debug("Developers are: " + this.developers.toString()); //$NON-NLS-1$ logger.debug("Contributors are: " + this.contributors.toString()); //$NON-NLS-1$ } return null; }
From source file:org.boretti.drools.integration.drools5.DroolsHelper.java
License:Open Source License
public static PackageBuilder getPackageBuilder(Log logger, MavenProject project) throws MojoExecutionException { if (logger.isDebugEnabled()) logger.debug("starting creation of package builder"); ClassLoader loader = DroolsHelper.class.getClassLoader(); List<?> classpathFiles = null; try {//from ww w. j a va 2 s.co m classpathFiles = project.getRuntimeClasspathElements(); } catch (Exception e) { throw new MojoExecutionException("Error during build " + e.getMessage(), e); } URL[] urls = new URL[classpathFiles.size()]; for (int i = 0; i < classpathFiles.size(); ++i) { try { urls[i] = new File((String) classpathFiles.get(i)).toURI().toURL(); } catch (MalformedURLException e) { throw new MojoExecutionException("Error during build " + e.getMessage(), e); } } URLClassLoader ucl = new URLClassLoader(urls, loader); PackageBuilderConfiguration conf = new PackageBuilderConfiguration(); conf.setClassLoader(ucl); return new PackageBuilder(conf); }
From source file:org.boretti.drools.integration.drools5.DroolsHelper.java
License:Open Source License
public static boolean compileSourceFile(Log logger, MavenProject project, File src, File dest, boolean xml, DroolsGoalExecutionLogs dgel) throws MojoExecutionException { if (logger.isDebugEnabled()) logger.debug("starting compilation of source file " + src); PackageBuilder builder = getPackageBuilder(logger, project); try {/*from w w w .j a va2 s .co m*/ InputStreamReader instream = new InputStreamReader(new FileInputStream(src)); if (xml) builder.addPackageFromXml(instream); else builder.addPackageFromDrl(instream); if (!validationError(logger, builder.getErrors(), src)) return false; dest.getParentFile().mkdirs(); Package dpackage = builder.getPackage(); ObjectOutputStream outstream = new ObjectOutputStream(new FileOutputStream(dest)); outstream.writeObject(dpackage); if (outstream != null) outstream.close(); dgel.getLogs().add(new DroolsGoalExecutionLog(src.getAbsolutePath(), "compile", "Compiling file " + src.getAbsolutePath() + " to " + dest.getAbsolutePath())); return true; } catch (FileNotFoundException e) { throw new MojoExecutionException("Error because of file not found " + e.getMessage(), e); } catch (DroolsParserException e) { if (!validationError(logger, builder.getErrors(), src)) return false; throw new MojoExecutionException("Error because of unexpected drools error " + e.getMessage(), e); } catch (IOException e) { throw new MojoExecutionException("Error because of IO Error " + e.getMessage(), e); } }
From source file:org.boretti.drools.integration.drools5.DroolsHelper.java
License:Open Source License
public static boolean validateSourceFile(Log logger, MavenProject project, File src, boolean xml, DroolsGoalExecutionLogs dgel) throws MojoExecutionException { if (logger.isDebugEnabled()) logger.debug("starting validation of source file " + src); PackageBuilder builder = getPackageBuilder(logger, project); try {/*ww w .j av a 2s .com*/ InputStreamReader instream = new InputStreamReader(new FileInputStream(src)); if (xml) builder.addPackageFromXml(instream); else builder.addPackageFromDrl(instream); dgel.getLogs().add(new DroolsGoalExecutionLog(src.getAbsolutePath(), "validate", "Validate file " + src.getAbsolutePath())); return validationError(logger, builder.getErrors(), src); } catch (FileNotFoundException e) { throw new MojoExecutionException("Error because of file not found " + e.getMessage(), e); } catch (DroolsParserException e) { if (!validationError(logger, builder.getErrors(), src)) return false; throw new MojoExecutionException("Error because of unexpected drools error " + e.getMessage(), e); } catch (IOException e) { throw new MojoExecutionException("Error because of IO Error " + e.getMessage(), e); } }
From source file:org.buildforce.tomcat.util.FileSystemUtils.java
License:Apache License
/** * Deletes the specified file set. If the base directory of the file set is relative, it will be resolved against * the base directory of the current project. * * @param fileset The file set to delete, must not be <code>null</code>. * @throws MojoExecutionException When the file set failed to get deleted. *//*from w ww .j a v a2 s . com*/ public static void removeFileSet(org.apache.maven.shared.model.fileset.FileSet fileset, Log log) throws MojoExecutionException { try { File dir = new File(fileset.getDirectory()).getAbsoluteFile(); if (!dir.exists()) { log.debug("Skipping non-existing directory: " + dir); return; } if (!dir.isDirectory()) { throw new MojoExecutionException(dir + " is not a directory."); } log.info("Deleting " + fileset.getDirectory()); FileSetManager fileSetManager = new FileSetManager(log, true); fileSetManager.delete(fileset); } catch (IOException e) { throw new MojoExecutionException( "Failed to delete directory: " + fileset.getDirectory() + ". Reason: " + e.getMessage(), e); } catch (IllegalStateException e) { // TODO: IOException from plexus-utils should be acceptable here throw new MojoExecutionException( "Failed to delete directory: " + fileset.getDirectory() + ". Reason: " + e.getMessage(), e); } }
From source file:org.bytedeco.javacpp.tools.BuildMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException { final Log log = getLog(); try {/* w ww .j a v a2s .com*/ if (log.isDebugEnabled()) { log.debug("classPath: " + classPath); log.debug("classPaths: " + Arrays.deepToString(classPaths)); log.debug("includePath: " + includePath); log.debug("includePaths: " + Arrays.deepToString(includePaths)); log.debug("linkPath: " + linkPath); log.debug("linkPaths: " + Arrays.deepToString(linkPaths)); log.debug("preloadPath: " + preloadPath); log.debug("preloadPaths: " + Arrays.deepToString(preloadPaths)); log.debug("outputDirectory: " + outputDirectory); log.debug("outputName: " + outputName); log.debug("compile: " + compile); log.debug("deleteJniFiles: " + deleteJniFiles); log.debug("header: " + header); log.debug("copyLibs: " + copyLibs); log.debug("jarPrefix: " + jarPrefix); log.debug("properties: " + properties); log.debug("propertyFile: " + propertyFile); log.debug("propertyKeysAndValues: " + propertyKeysAndValues); log.debug("classOrPackageName: " + classOrPackageName); log.debug("classOrPackageNames: " + Arrays.deepToString(classOrPackageNames)); log.debug("environmentVariables: " + environmentVariables); log.debug("compilerOptions: " + Arrays.deepToString(compilerOptions)); log.debug("skip: " + skip); } if (skip) { log.info("Skipping execution of JavaCPP Builder"); return; } classPaths = merge(classPaths, classPath); classOrPackageNames = merge(classOrPackageNames, classOrPackageName); Logger logger = new Logger() { @Override public void debug(String s) { log.debug(s); } @Override public void info(String s) { log.info(s); } @Override public void warn(String s) { log.warn(s); } @Override public void error(String s) { log.error(s); } }; Builder builder = new Builder(logger).classPaths(classPaths).outputDirectory(outputDirectory) .outputName(outputName).compile(compile).deleteJniFiles(deleteJniFiles).header(header) .copyLibs(copyLibs).jarPrefix(jarPrefix).properties(properties).propertyFile(propertyFile) .properties(propertyKeysAndValues).classesOrPackages(classOrPackageNames) .environmentVariables(environmentVariables).compilerOptions(compilerOptions); Properties properties = builder.properties; log.info("Detected platform \"" + Loader.getPlatform() + "\""); log.info("Building for platform \"" + properties.get("platform") + "\""); String separator = properties.getProperty("platform.path.separator"); for (String s : merge(includePaths, includePath)) { String v = properties.getProperty("platform.includepath", ""); properties.setProperty("platform.includepath", v.length() == 0 || v.endsWith(separator) ? v + s : v + separator + s); } for (String s : merge(linkPaths, linkPath)) { String v = properties.getProperty("platform.linkpath", ""); properties.setProperty("platform.linkpath", v.length() == 0 || v.endsWith(separator) ? v + s : v + separator + s); } for (String s : merge(preloadPaths, preloadPath)) { String v = properties.getProperty("platform.preloadpath", ""); properties.setProperty("platform.preloadpath", v.length() == 0 || v.endsWith(separator) ? v + s : v + separator + s); } Properties projectProperties = project.getProperties(); for (String key : properties.stringPropertyNames()) { projectProperties.setProperty("javacpp." + key, properties.getProperty(key)); } File[] outputFiles = builder.build(); if (log.isDebugEnabled()) { log.debug("outputFiles: " + Arrays.deepToString(outputFiles)); } } catch (IOException | ClassNotFoundException | NoClassDefFoundError | InterruptedException | ParserException e) { log.error("Failed to execute JavaCPP Builder: " + e.getMessage()); throw new MojoExecutionException("Failed to execute JavaCPP Builder", e); } }
From source file:org.callistasoftware.maven.plugins.propertyscanner.MyMojo.java
License:Apache License
private Properties loadProperties(Log logger) throws MojoExecutionException { FilenameFilter filter = new SuffixFileFilter(".properties"); Properties allProperties = new Properties(); for (File propertiesDirectory : propertiesDirectories) { if (!propertiesDirectory.exists()) { throw new MojoExecutionException("Could not find properties directory: " + propertiesDirectory); }//from w w w. j a v a 2 s .co m File[] propertiesFiles = propertiesDirectory.listFiles(filter); for (File propertiesFile : propertiesFiles) { if (!propertiesFile.exists()) { throw new MojoExecutionException("Could not find properties file: " + propertiesFile); } //loading properties Properties properties = new Properties(); FileReader r = null; try { r = new FileReader(propertiesFile); properties.load(r); } catch (IOException e) { throw new MojoExecutionException( "Error loading properties from translation file: " + propertiesFile, e); } finally { try { r.close(); } catch (Exception e) { //nothing } } logger.debug("Loaded properties, read " + properties.size() + " entries"); allProperties.putAll(properties); } } logger.info("Total properties loaded: " + allProperties.size()); return allProperties; }
From source file:org.codehaus.cargo.maven2.configuration.AbstractDependency.java
License:Apache License
/** * Find artifact location for the artifact of this dependency. * @param artifacts All artifacts' list. * @param log Logger./*from w w w . java 2 s. co m*/ * @return Artifact location. * @throws MojoExecutionException If resolve fails. */ protected String findArtifactLocation(Set<Artifact> artifacts, Log log) throws MojoExecutionException { Artifact resolvedArtifact = null; log.debug("Searching for an artifact that matches [" + getGroupId() + ":" + getArtifactId() + ":" + getType() + ":" + getClassifier() + "]..."); for (Artifact artifact : artifacts) { log.debug("Checking artifact [" + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + ":" + artifact.getClassifier() + "]..."); // TODO: Find a better to handle match between m2 types and cargo types... if (artifact.getGroupId().equals(getGroupId()) && artifact.getArtifactId().equals(getArtifactId())) { if (artifact.getClassifier() == getClassifier() || artifact.getClassifier() != null && artifact.getClassifier().equals(getClassifier())) { String artifactType = artifact.getType(); if (artifactType == null || DeployableType.EJB.getType().equals(artifactType)) { artifactType = "jar"; } String type = getType(); if (type == null || DeployableType.BUNDLE.getType().equals(type) || DeployableType.EJB.getType().equals(type)) { type = "jar"; } if (type.equals(artifactType)) { resolvedArtifact = artifact; break; } } } } if (resolvedArtifact == null) { throw new MojoExecutionException("Artifact [" + getGroupId() + ":" + getArtifactId() + ":" + getType() + "] is not a dependency of the project."); } if (resolvedArtifact.getFile() == null) { throw new MojoExecutionException( "The file for artifact [" + resolvedArtifact + " is null (probably does not exist)."); } return resolvedArtifact.getFile().getPath(); }