List of usage examples for org.apache.maven.plugin.logging Log debug
void debug(Throwable error);
From source file:net.officefloor.maven.OpenOfficeFloorGoal.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { // Ensure have required values ensureNotNull("Must have project", this.project); ensureNotNull("Must have plug-in dependencies", this.pluginDependencies); ensureNotNull("Port not configured for the " + OfficeBuilding.class.getSimpleName(), this.port); ensureNotNull(OfficeFloor.class.getSimpleName() + " configuration location not specified", this.officeFloorLocation); // Ensure default non-required values this.processName = defaultValue(this.processName, this.defaultProcessName); // Obtain the OfficeBuilding manager OfficeBuildingManagerMBean officeBuildingManager; try {/*from w w w. j av a 2 s.c o m*/ officeBuildingManager = OfficeBuildingManager.getOfficeBuildingManager(null, this.port.intValue(), StartOfficeBuildingGoal.getKeyStoreFile(), StartOfficeBuildingGoal.KEY_STORE_PASSWORD, StartOfficeBuildingGoal.USER_NAME, StartOfficeBuildingGoal.PASSWORD); } catch (Throwable ex) { throw newMojoExecutionException("Failed accessing the " + OfficeBuilding.class.getSimpleName(), ex); } // Create the open OfficeFloor configuration OpenOfficeFloorConfiguration configuration = new OpenOfficeFloorConfiguration(this.officeFloorLocation); configuration.setOfficeFloorSourceClassName(this.officeFloorSource); configuration.setProcessName(this.processName); // Provide JVM options (if specified) if (this.jvmOptions != null) { for (String jvmOption : this.jvmOptions) { configuration.addJvmOption(jvmOption); } } // Add class path of project try { List<String> elements = this.project.getRuntimeClasspathElements(); for (String element : elements) { configuration.addClassPathEntry(element); } } catch (Throwable ex) { throw newMojoExecutionException( "Failed creating class path for the " + OfficeFloor.class.getSimpleName(), ex); } // Add additional class path entries for (String classPathEntry : this.classPathEntries) { configuration.addClassPathEntry(classPathEntry); } // Indicate the configuration Log log = this.getLog(); log.debug(OfficeFloorSource.class.getSimpleName() + " configuration:"); log.debug("\tProcess name = " + configuration.getProcessName()); log.debug("\t" + OfficeFloorSource.class.getSimpleName() + " class = " + configuration.getOfficeFloorSourceClassName()); log.debug("\t" + OfficeFloorSource.class.getSimpleName() + " location = " + configuration.getOfficeFloorLocation()); log.debug("\tProperties:"); Properties configurationOfficeFloorProperties = configuration.getOfficeFloorProperties(); for (String propertyName : configurationOfficeFloorProperties.stringPropertyNames()) { log.debug("\t\t" + propertyName + " = " + configurationOfficeFloorProperties.getProperty(propertyName)); } log.debug("\tClass path entries:"); for (String classPathEntry : configuration.getClassPathEntries()) { log.debug("\t\t" + classPathEntry); } log.debug("\tUpload Artifacts:"); for (UploadArtifact uploadArtifact : configuration.getUploadArtifacts()) { log.debug("\t\t" + uploadArtifact.getName()); } log.debug("\tJVM options:"); for (String jvmOption : configuration.getJvmOptions()) { log.debug("\t\t" + jvmOption); } log.debug("\tInitial task = " + configuration.getOfficeName() + " " + configuration.getWorkName() + "." + configuration.getTaskName() + "(" + configuration.getParameter() + ")"); // Open the OfficeFloor String processNameSpace; try { processNameSpace = officeBuildingManager.openOfficeFloor(configuration); } catch (Throwable ex) { throw newMojoExecutionException("Failed opening the " + OfficeFloor.class.getSimpleName(), ex); } // Log opened the OfficeFloor this.getLog().info("Opened " + OfficeFloor.class.getSimpleName() + " under process name space '" + processNameSpace + "' for " + this.officeFloorLocation); }
From source file:net.officefloor.maven.StartOfficeBuildingGoal.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { // Ensure have configured values ensureNotNull("Must have project", this.project); ensureNotNull("Must have plug-in dependencies", this.pluginDependencies); ensureNotNull("Must have local repository", this.localRepository); ensureNotNull("Must have repository system", this.repositorySystem); ensureNotNull("Port not configured for the " + OfficeBuilding.class.getSimpleName(), this.port); // Indicate the configuration final Log log = this.getLog(); log.debug(OfficeBuilding.class.getSimpleName() + " configuration:"); log.debug("\tPort = " + this.port); // Create the environment properties Properties environment = new Properties(); environment.putAll(this.project.getProperties()); // Log the properties log.debug("\tProperties:"); for (String propertyName : environment.stringPropertyNames()) { log.debug("\t\t" + propertyName + " = " + environment.getProperty(propertyName)); }// w w w.j av a 2 s.c o m // Obtain the plugin dependency inclusions List<Artifact> artifactInclusions = new ArrayList<Artifact>(this.pluginDependencies.size()); for (PluginDependencyInclusion inclusion : this.dependencyInclusions) { // Must match on dependency for inclusion Artifact includedDependency = null; for (Artifact dependency : this.pluginDependencies) { if ((inclusion.groupId.equals(dependency.getGroupId())) && (inclusion.artifactId.equals(dependency.getArtifactId())) && (inclusion.type.equals(dependency.getType())) && ((inclusion.classifier == null) || (inclusion.classifier.equals(dependency.getClassifier())))) { // Found the dependency to include includedDependency = dependency; } } // Ensure have dependency for inclusion if (includedDependency == null) { throw newMojoExecutionException("Failed to obtain plug-in dependency " + inclusion.groupId + ":" + inclusion.artifactId + (inclusion.classifier == null ? "" : ":" + inclusion.classifier) + ":" + inclusion.type, null); } // Include the dependency artifactInclusions.add(includedDependency); } // Obtain the class path for OfficeBuilding String classPath = null; try { // Indicate the remote repositories log.debug("\tRemote repositories:"); // Obtain remote repositories and load to class path factory List<RemoteRepository> remoteRepositories = new LinkedList<RemoteRepository>(); List<String> urls = new LinkedList<String>(); for (Object object : this.project.getRemoteArtifactRepositories()) { ArtifactRepository repository = (ArtifactRepository) object; String remoteRepositoryUrl = repository.getUrl(); remoteRepositories.add(new RemoteRepository(repository.getId(), repository.getLayout().getId(), remoteRepositoryUrl)); urls.add(remoteRepositoryUrl); // Indicate the remote repository log.debug("\t\t" + remoteRepositoryUrl); } // Create the class path factory and add remote repositories File localRepositoryDirectory = new File(this.localRepository.getBasedir()); ClassPathFactory classPathFactory = new ClassPathFactoryImpl(this.plexusContainer, this.repositorySystem, localRepositoryDirectory, remoteRepositories.toArray(new RemoteRepository[remoteRepositories.size()])); // Indicate the class path log.debug("\tClass path:"); // Obtain the class path entries for each included artifact List<String> classPathEntries = new LinkedList<String>(); for (Artifact dependency : artifactInclusions) { // Obtain the class path entries for the dependency String[] entries = classPathFactory.createArtifactClassPath(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getType(), dependency.getClassifier()); // Uniquely include the class path entries for (String entry : entries) { if (classPathEntries.contains(entry)) { continue; // ignore as already included } classPathEntries.add(entry); // Indicate class path entry log.debug("\t\t" + entry); } } // Obtain the class path classPath = ClassPathFactoryImpl.transformClassPathEntriesToClassPath( classPathEntries.toArray(new String[classPathEntries.size()])); } catch (Exception ex) { throw newMojoExecutionException("Failed obtaining dependencies for launching OfficeBuilding", ex); } // Create the process configuration ProcessConfiguration configuration = new ProcessConfiguration(); configuration.setAdditionalClassPath(classPath); // Write output to file configuration.setProcessOutputStreamFactory(new ProcessOutputStreamFactory() { @Override public OutputStream createStandardProcessOutputStream(String processNamespace, String[] command) throws IOException { // Log the command StringBuilder commandLine = new StringBuilder(); commandLine.append(OfficeBuilding.class.getSimpleName() + " command line:"); for (String commandItem : command) { commandLine.append(" "); commandLine.append(commandItem); } log.debug(commandLine); // Return the output stream return this.getOutputStream(processNamespace); } @Override public OutputStream createErrorProcessOutputStream(String processNamespace) throws IOException { return this.getOutputStream(processNamespace); } /** * Lazy instantiated {@link OutputStream}. */ private OutputStream outputStream = null; /** * Obtains the {@link OutputStream}. * * @param processNamespace * Process name space. * @return {@link OutputStream}. * @throws IOException * If fails to obtain the {@link OutputStream}. */ private synchronized OutputStream getOutputStream(String processNamespace) throws IOException { // Lazy instantiate the output stream if (this.outputStream == null) { // Create the output file File file = File.createTempFile(processNamespace, ".log"); this.outputStream = new FileOutputStream(file); // Log that outputting to file log.info("Logging " + OfficeBuilding.class.getSimpleName() + " output to file " + file.getAbsolutePath()); } // Return the output stream return this.outputStream; } }); // Start the OfficeBuilding try { OfficeBuildingManager.spawnOfficeBuilding(null, this.port.intValue(), getKeyStoreFile(), KEY_STORE_PASSWORD, USER_NAME, PASSWORD, null, false, environment, null, true, configuration); } catch (Throwable ex) { // Provide details of the failure final String MESSAGE = "Failed starting the " + OfficeBuilding.class.getSimpleName(); this.getLog().error(MESSAGE + ": " + ex.getMessage() + " [" + ex.getClass().getSimpleName() + "]"); this.getLog().error("DIAGNOSIS INFORMATION:"); this.getLog().error(" classpath='" + System.getProperty("java.class.path") + "'"); this.getLog().error(" additional classpath='" + classPath + "'"); // Propagate the failure throw newMojoExecutionException(MESSAGE, ex); } // Log started OfficeBuilding this.getLog().info("Started " + OfficeBuilding.class.getSimpleName() + " on port " + this.port.intValue()); }
From source file:net.oneandone.maven.plugins.prerelease.core.Archive.java
License:Apache License
/** * @param timeout in seconds; -1 to try only once and never wait. * @param log may be null/*from w ww . j av a 2 s. c o m*/ */ private void open(int timeout, Log log) throws IOException { FileNode file; int seconds; if (opened) { throw new IllegalStateException(); } file = lockFile(); try { seconds = 0; while (true) { // every time - if someone wiped the primary storage directory file.getParent().mkdirsOpt(); try { file.mkfile(); OnShutdown.get().deleteAtExit(file); opened = true; file.writeString(Integer.toString(pid())); if (log != null) { log.debug("locked for pid " + pid()); } return; } catch (MkfileException e) { if (seconds > timeout) { if (log != null) { log.warn("Lock timed out after " + seconds + "s."); } throw e; } if (seconds % 10 == 0) { if (log != null) { log.info("Waiting for " + file + ": " + seconds + "s"); log.debug(e); } } seconds++; Thread.sleep(1000); } } } catch (InterruptedException e) { if (log != null) { log.warn("interrupted"); } } }
From source file:net.oneandone.maven.plugins.prerelease.core.Prerelease.java
License:Apache License
public static Prerelease create(Maven maven, Map<String, String> propertyArgs, Log log, Descriptor descriptor, Target target) throws Exception { Prerelease prerelease;//from w w w.j av a 2 s . co m FileNode tags; FileNode checkout; String tagname; String tagbase; int idx; log.info("creating un-committed tag ..."); if (descriptor.svnTag.endsWith("/")) { throw new IllegalArgumentException(descriptor.svnTag); } idx = descriptor.svnTag.lastIndexOf('/'); if (idx == -1) { throw new IllegalArgumentException(descriptor.svnTag); } tagbase = descriptor.svnTag.substring(0, idx); tagname = descriptor.svnTag.substring(idx + 1); target.create(); try { tags = target.join("tags"); checkout = tags.join(tagname); log.debug(target.svnLauncher("checkout", "--depth=empty", tagbase, tags.getAbsolute()).exec()); log.debug(target .svnLauncher("copy", "-r" + descriptor.revision, descriptor.svnOrig, checkout.getAbsolute()) .exec()); prerelease = new Prerelease(target, checkout, descriptor); prerelease.descriptor.save(target); Transform.adjustPom(prerelease.checkout.join("pom.xml"), descriptor.previous, descriptor.project.version, descriptor.svnOrig, descriptor.svnTag); Archive.adjustChangesOpt(prerelease.checkout, prerelease.descriptor.project.version); prerelease.create(maven, propertyArgs); log.info("created prerelease in " + prerelease.target); } catch (Exception e) { target.scheduleRemove(log, "create failed: " + e.getMessage()); throw e; } return prerelease; }
From source file:net.oneandone.maven.plugins.prerelease.core.Prerelease.java
License:Apache License
/** commit before deploy - because if deployment fails, we can reliably revert the commit. */ private void promoteLocked(Log log, Map<String, String> propertyArgs, String commitTagMessage, String revertTagMessage, String commitNextMessage, FileNode origCommit, Maven maven) throws Exception { FileNode installed;//from ww w .ja va2 s. com commit(log, renderMessage(commitTagMessage)); try { maven.deployPrerelease(log, propertyArgs, this); } catch (Exception e) { log.info("deployment failed - reverting tag"); revertCommit(log, renderMessage(revertTagMessage)); target.scheduleRemove(log, "deployment failed (tag has been reverted): " + e.getMessage()); throw e; } // local install installed = descriptor.project.localRepo(maven); installed.deleteTreeOpt(); artifacts().move(installed); try { log.info("Update pom and changes ..."); log.debug(Subversion.launcher(origCommit, "commit", "-m", renderMessage(commitNextMessage)).exec()); origCommit.deleteTree(); // Move prerelease directory into REMOVE directory because it's invalid now: // tag was committed, and artifacts have been deployed. It's not removed immediately to make // distribution file available locally. target.scheduleRemove(log, "prerelease has been promoted"); } catch (Exception e) { log.warn("Promote succeeded: your artifacts have been deployed, and your svn tag was created. "); log.warn("However, some post-release step failed with this exception:"); log.warn(e); log.warn("Thus, you can use your release, but someone should have a look at this exception."); } }
From source file:net.oneandone.maven.plugins.prerelease.ProjectBase.java
License:Apache License
protected WorkingCopy checkedWorkingCopy() throws Exception { Log log; WorkingCopy workingCopy;/* w ww .ja v a2 s.c om*/ log = getLog(); log.info("checking working copy ..."); workingCopy = WorkingCopy.load(basedir()); if (log.isDebugEnabled()) { log.debug("revisions: " + workingCopy.revisions); log.debug("changes: " + workingCopy.changes); } workingCopy.check(); return workingCopy; }
From source file:net.oneandone.maven.plugins.prerelease.util.Subversion.java
License:Apache License
public static void sparseCheckout(Log log, FileNode result, String svnurl, String revision, boolean tryChanges) throws Failure { log.debug(Subversion .launcher(result.getParent(), "co", "-r", revision, "--depth", "empty", svnurl, result.getName()) .exec());/*from w ww .jav a 2s. c o m*/ log.debug(Subversion.launcher(result, "up", "-r", revision, "pom.xml").exec()); if (tryChanges) { log.debug(Subversion.launcher(result, "up", "-r", revision, "--depth", "empty", "src").exec()); log.debug(Subversion.launcher(result, "up", "-r", revision, "--depth", "empty", "src/changes").exec()); log.debug(Subversion.launcher(result, "up", "-r", revision, "src/changes/changes.xml").exec()); } }
From source file:net.oneandone.maven.rules.common.AbstractRule.java
License:Apache License
/** * Returns true if rules is defined in this project or a parent that is not part of the multi module *///from ww w.j a v a 2 s .c om protected boolean ruleIsDefinedInProjectOrNotModuleParent(MavenProject project, Log log) { if (project == null) { return false; } log.debug("<<< " + project.toString() + " >>>"); log.debug("project Parent: " + project.getParent()); log.debug("project orig Model Parent: " + project.getOriginalModel().getParent()); if (ruleDefinedInProject(project)) { return true; } else if (!projectIsSubmodule(project, log)) { return ruleIsDefinedInProjectOrNotModuleParent(project.getParent(), log); } else { return false; } }
From source file:net.onedaybeard.agrotera.maven.ComponentMatrix.java
License:Apache License
@Override public void execute() throws MojoExecutionException { long then = System.currentTimeMillis(); Log log = getLog(); /**//www. j a va2s.c o m * Create Resolver for all classes on the classpath; including dependencies */ List<URL> classPathURLS = new ArrayList<URL>(); List<String> classpathElements = null; try { classpathElements = project.getCompileClasspathElements(); List<URL> projectClasspathList = new ArrayList<URL>(); for (String element : classpathElements) { // Check if part of the exclusion list boolean found = false; for (String key : EXCLUSION_LIST) { if (element.contains(key)) { found = true; break; } } if (found) { log.debug(String.format("ComponentMatrix::execute() skipping class path: %s", element)); continue; } try { URL url = new File(element).toURI().toURL(); log.debug(String.format("ComponentMatrix::execute() adding class path: %s", element)); projectClasspathList.add(url); } catch (MalformedURLException e) { throw new MojoExecutionException(element + " is an invalid classpath element", e); } } classPathURLS.addAll(projectClasspathList); } catch (DependencyResolutionRequiredException e) { new MojoExecutionException("Dependency resolution failed", e); } /** * Creates a class loader with all dependencies * TODO: Restrict this only to those dependencies which are interesting * COMMENT #1: Can't just do INCLUSION, might forget some class paths which are needed for type resolvement. * COMMENT #2: Just restrict to package-phase; don't care about 1 or 2 second generation then. */ URLClassLoader urlcl = new URLClassLoader(classPathURLS.toArray(new URL[0]), Thread.currentThread().getContextClassLoader()); Reflections reflections = new Reflections( new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader(urlcl)).addClassLoader(urlcl)); /** * Populate all required fields, Systems, Templates and Components */ ArrayList<Class<?>> artemisSystems = new ArrayList<Class<?>>( reflections.getTypesAnnotatedWith(ArtemisSystem.class)); ArrayList<Class<?>> artemisTemplates = new ArrayList<Class<?>>( reflections.getTypesAnnotatedWith(ArtemisTemplate.class)); ArrayList<Class<?>> components = new ArrayList<Class<?>>( reflections.getSubTypesOf(com.artemis.Component.class)); ArrayList<Class<?>> managers = new ArrayList<Class<?>>( reflections.getSubTypesOf(com.artemis.Manager.class)); // Sort on simple name (class name) Comparator<Class<?>> lexicalCompare = new Comparator<Class<?>>() { @Override public int compare(Class<?> arg0, Class<?> arg1) { return arg0.getSimpleName().compareTo(arg1.getSimpleName()); } }; Comparator<Class<?>> packageCompare = new Comparator<Class<?>>() { @Override public int compare(Class<?> arg0, Class<?> arg1) { return arg0.getName().compareTo(arg1.getName()); } }; // Sort everything and create strings for export Collections.sort(artemisSystems, packageCompare); Collections.sort(artemisTemplates, lexicalCompare); Collections.sort(components, lexicalCompare); ArrayList<String> componentsStr = convertToString(components); ArrayList<String> templatesStr = convertToString(artemisTemplates); /** * Create the Rows, and create Strings * TODO: Create better hierarchical representation? */ ArrayList<SystemRow> rows = new ArrayList<SystemRow>(); Class prev = String.class; // Prev is a nonsensical class the package of which we can never be in for (Class system : artemisSystems) { // See if we need to add a name row Package curPack = system.getPackage(); Package prevPack = prev.getPackage(); if (curPack != prevPack) { // Create the difference string between the current and last package String constructDiffPackage = constructDiffPackage(prevPack, curPack); System.err.println(constructDiffPackage); rows.add(new SystemRow(constructDiffPackage)); prev = system; } rows.add(new SystemRow(system, components)); } Theme theme = new Theme(); Chunk chunk = theme.makeChunk("altMatrix"); chunk.set("longestName", MatrixStringUtil.findLongestString(components).replaceAll(".", "_") + "______"); chunk.set("longestManagers", MatrixStringUtil.findLongestString(managers).replaceAll(".", "_")); chunk.set("longestSystems", MatrixStringUtil.findLongestString(artemisSystems).replaceAll(".", "_")); chunk.set("systems", rows); chunk.set("headers", componentsStr); chunk.set("templates", templatesStr); chunk.set("project", name); BufferedWriter out = null; try { System.err.println("Writing to: " + saveDirectory); out = new BufferedWriter(new FileWriter(new File(saveDirectory, "altMatrix.html"))); chunk.render(out); } catch (IOException e) { e.printStackTrace(); } finally { if (out != null) try { out.close(); } catch (IOException e) { e.printStackTrace(); } } log.debug(String.format("ComponentMatrix::execute() matrix generation took: %.4f s", (System.currentTimeMillis() - then) / 1000f)); }
From source file:net.revelc.code.formatter.FormatterMojo.java
License:Apache License
/** * Format individual file./*www . jav a2 s. c o m*/ * * @param file the file * @param rc the rc * @param hashCache the hash cache * @param basedirPath the basedir path * @throws IOException Signals that an I/O exception has occurred. * @throws BadLocationException the bad location exception * @throws MojoFailureException * @throws MojoExecutionException */ protected void doFormatFile(File file, ResultCollector rc, Properties hashCache, String basedirPath, boolean dryRun) throws IOException, BadLocationException, MojoFailureException, MojoExecutionException { Log log = getLog(); log.debug("Processing file: " + file); String code = readFileAsString(file); String originalHash = md5hash(code); String canonicalPath = file.getCanonicalPath(); String path = canonicalPath.substring(basedirPath.length()); String cachedHash = hashCache.getProperty(path); if (cachedHash != null && cachedHash.equals(originalHash)) { rc.skippedCount++; log.debug("File is already formatted."); return; } Result r; if (file.getName().endsWith(".java")) { r = this.javaFormatter.formatFile(file, this.lineEnding, dryRun); } else { r = this.jsFormatter.formatFile(file, this.lineEnding, dryRun); } switch (r) { case SKIPPED: rc.skippedCount++; break; case SUCCESS: rc.successCount++; break; case FAIL: rc.failCount++; break; default: break; } String formattedCode = readFileAsString(file); String formattedHash = md5hash(formattedCode); hashCache.setProperty(path, formattedHash); if (originalHash.equals(formattedHash)) { rc.skippedCount++; log.debug("Equal hash code. Not writing result to file."); return; } writeStringToFile(formattedCode, file); }