List of usage examples for org.apache.maven.plugin.logging Log debug
void debug(Throwable error);
From source file:de.thetaphi.forbiddenapis.AbstractCheckMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { final Log log = getLog(); if (skip) {//from w w w.j a v a2s . com log.info("Skipping forbidden-apis checks."); return; } // In multi-module projects, one may want to configure the plugin in the parent/root POM. // However, it should not be executed for this type of POMs. if ("pom".equals(packaging)) { log.info("Skipping execution for packaging \"" + packaging + "\""); return; } // set default param: if (includes == null) includes = new String[] { "**/*.class" }; final URL[] urls; try { final List<String> cp = getClassPathElements(); urls = new URL[cp.size()]; int i = 0; for (final String cpElement : cp) { urls[i++] = new File(cpElement).toURI().toURL(); } assert i == urls.length; if (log.isDebugEnabled()) log.debug("Compile Classpath: " + Arrays.toString(urls)); } catch (MalformedURLException e) { throw new MojoExecutionException("Failed to build classpath: " + e); } URLClassLoader urlLoader = null; final ClassLoader loader = (urls.length > 0) ? (urlLoader = URLClassLoader.newInstance(urls, ClassLoader.getSystemClassLoader())) : ClassLoader.getSystemClassLoader(); try { final EnumSet<Checker.Option> options = EnumSet.noneOf(Checker.Option.class); if (internalRuntimeForbidden) options.add(INTERNAL_RUNTIME_FORBIDDEN); if (failOnMissingClasses) options.add(FAIL_ON_MISSING_CLASSES); if (failOnViolation) options.add(FAIL_ON_VIOLATION); if (failOnUnresolvableSignatures) options.add(FAIL_ON_UNRESOLVABLE_SIGNATURES); final Checker checker = new Checker(loader, options) { @Override protected void logError(String msg) { log.error(msg); } @Override protected void logWarn(String msg) { log.warn(msg); } @Override protected void logInfo(String msg) { log.info(msg); } }; if (!checker.isSupportedJDK) { final String msg = String.format(Locale.ENGLISH, "Your Java runtime (%s %s) is not supported by the forbiddenapis MOJO. Please run the checks with a supported JDK!", System.getProperty("java.runtime.name"), System.getProperty("java.runtime.version")); if (failOnUnsupportedJava) { throw new MojoExecutionException(msg); } else { log.warn(msg); return; } } if (suppressAnnotations != null) { for (String a : suppressAnnotations) { checker.addSuppressAnnotation(a); } } log.info("Scanning for classes to check..."); final File classesDirectory = getClassesDirectory(); if (!classesDirectory.exists()) { log.warn("Classes directory does not exist, forbiddenapis check skipped: " + classesDirectory); return; } final DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(classesDirectory); ds.setCaseSensitive(true); ds.setIncludes(includes); ds.setExcludes(excludes); ds.addDefaultExcludes(); ds.scan(); final String[] files = ds.getIncludedFiles(); if (files.length == 0) { log.warn(String.format(Locale.ENGLISH, "No classes found in '%s' (includes=%s, excludes=%s), forbiddenapis check skipped.", classesDirectory.toString(), Arrays.toString(includes), Arrays.toString(excludes))); return; } try { final String sig = (signatures != null) ? signatures.trim() : null; if (sig != null && sig.length() != 0) { log.info("Reading inline API signatures..."); checker.parseSignaturesString(sig); } if (bundledSignatures != null) { String targetVersion = getTargetVersion(); if ("".equals(targetVersion)) targetVersion = null; if (targetVersion == null) { log.warn("The 'targetVersion' parameter or '${maven.compiler.target}' property is missing. " + "Trying to read bundled JDK signatures without compiler target. " + "You have to explicitely specify the version in the resource name."); } for (String bs : bundledSignatures) { log.info("Reading bundled API signatures: " + bs); checker.parseBundledSignatures(bs, targetVersion); } } if (signaturesFiles != null) for (final File f : signaturesFiles) { log.info("Reading API signatures: " + f); checker.parseSignaturesFile(new FileInputStream(f)); } } catch (IOException ioe) { throw new MojoExecutionException("IO problem while reading files with API signatures: " + ioe); } catch (ParseException pe) { throw new MojoExecutionException("Parsing signatures failed: " + pe.getMessage()); } if (checker.hasNoSignatures()) { if (failOnUnresolvableSignatures) { throw new MojoExecutionException( "No API signatures found; use parameters 'signatures', 'bundledSignatures', and/or 'signaturesFiles' to define those!"); } else { log.info("Skipping execution because no API signatures are available."); return; } } log.info("Loading classes to check..."); try { for (String f : files) { checker.addClassToCheck(new FileInputStream(new File(classesDirectory, f))); } } catch (IOException ioe) { throw new MojoExecutionException("Failed to load one of the given class files: " + ioe); } log.info("Scanning for API signatures and dependencies..."); try { checker.run(); } catch (ForbiddenApiException fae) { throw new MojoFailureException(fae.getMessage()); } } finally { // Java 7 supports closing URLClassLoader, so check for Closeable interface: if (urlLoader instanceof Closeable) try { ((Closeable) urlLoader).close(); } catch (IOException ioe) { // ignore } } }
From source file:fr.fastconnect.factory.tibco.bw.maven.InitializeMojo.java
License:Apache License
private static boolean findParentPath(File path, Log logger) throws IOException, XmlPullParserException { File pomPath = new File(path + File.separator + "pom.xml"); if (pomPath != null && pomPath.exists()) { logger.debug("pomPath: " + pomPath.getAbsolutePath()); Model m = POMManager.getModelFromPOM(pomPath, logger); return propertyExistsInModel(m, parentBasedirProperty); }/* ww w . j a v a 2s . c o m*/ logger.debug("find false"); return false; }
From source file:fr.fastconnect.factory.tibco.bw.maven.InitializeMojo.java
License:Apache License
protected static File getParent(MavenProject project, Log logger) throws IOException, XmlPullParserException { File result = null;// w ww. j a va2 s . c o m MavenProject parent = project.getParent(); if (parent == null) { return result; // no parent: return null } File parentPOM = parent.getFile(); File parentBasedir = null; if (parentPOM != null && parentPOM.getParentFile() != null && parentPOM.getParentFile().exists() && parentPOM.getParentFile().isDirectory()) { parentBasedir = parentPOM.getParentFile(); } if (parentPOM != null) { logger.debug("parentPOM: " + parentPOM.getAbsolutePath()); } while (parentBasedir != null && parentBasedir.exists()) { logger.debug("parentBasedir: " + parentBasedir.getAbsolutePath()); if (findParentPath(parentBasedir, logger)) { logger.debug("parentFound"); result = parentBasedir; break; } logger.debug("parentNotFound"); if (parent != null) { logger.debug(parent.getArtifactId()); parentBasedir = parent.getParentFile(); // use <relativePath> to retrieve real parent file if (parentBasedir == null && parent.getParent() != null) { parentBasedir = parent.getParent().getFile(); } if (parentBasedir != null) { logger.debug(parentBasedir.getAbsolutePath()); } if (parentBasedir != null && parentBasedir.exists() && parentBasedir.isFile()) { parentBasedir = parentBasedir.getParentFile(); } parent = parent.getParent(); } } return result; }
From source file:fr.husta.maven.plugin.ReleaseProjectVersionMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException { issueManagement = project.getIssueManagement(); Log tempLog = getLog(); if (issueManagement != null) { tempLog.debug("IssueManagement -> system = " + issueManagement.getSystem()); tempLog.debug("IssueManagement -> url = " + issueManagement.getUrl()); final String ISSUE_MNGT_MANTIS = "Mantis"; if (issueManagement.getSystem() != null && ISSUE_MNGT_MANTIS.equals(issueManagement.getSystem()) == false) { tempLog.warn("IssueManagement -> system should be set to '" + ISSUE_MNGT_MANTIS + "'."); }//from w w w . j a v a 2s . c o m } try { // connection to Mantis SOAP API MantisConnectPortType portType = MantisUtils.createConnector(getMantisSoapApiUrl()); MantisConnector mantisConnector = new MantisConnector(portType); tempLog.debug("projectName = '" + projectName + "'"); // find ProjectId from Name BigInteger projectId = mantisConnector.getProjectIdByName(login, password, projectName); tempLog.info("Project " + projectName + " has ID=" + projectId); String tempCurrentSnapshot = currentSnapshot; if (versionPrefix != null) { tempCurrentSnapshot = versionPrefix + "-" + tempCurrentSnapshot; } String tempReleaseVersion = releaseVersion; if (versionPrefix != null) { tempReleaseVersion = versionPrefix + "-" + tempReleaseVersion; } tempLog.info("Rename Version '" + tempCurrentSnapshot + "' to " + tempReleaseVersion); mantisConnector.renameVersion(tempLog, login, password, projectId, tempCurrentSnapshot, tempReleaseVersion); tempLog.info("Renamed Version '" + tempCurrentSnapshot + "' to " + tempReleaseVersion); // call to web service method String tempDevelopmentVersion = developmentVersion; if (versionPrefix != null) { tempDevelopmentVersion = versionPrefix + "-" + tempDevelopmentVersion; } tempLog.info("Create Version '" + tempDevelopmentVersion + "' in Mantis, releaseFlag=" + false); mantisConnector.addProjectVersion(login, password, projectId, tempDevelopmentVersion, false); tempLog.info("Version '" + tempDevelopmentVersion + "' created in Mantis, releaseFlag=" + false); } catch (ServiceException e) { tempLog.error(e.getMessage()); throw new MojoExecutionException(e.getMessage(), e); } catch (RuntimeException e) { tempLog.error(e.getMessage()); throw new MojoExecutionException(e.getMessage(), e); } catch (RemoteException e) { tempLog.error(e.getMessage()); throw new MojoExecutionException(e.getMessage(), e); } }
From source file:io.cloudslang.lang.enforcer.SpringCleansingRule.java
License:Open Source License
private void applyForJavaSourcesInRoot(final String path, final Log log) throws EnforcerRuleException { Iterator<File> fileIterator = iterateFiles(new File(path), new String[] { JAVA }, true); while (fileIterator.hasNext()) { File source = fileIterator.next(); if (isRegularFile(source.toPath(), NOFOLLOW_LINKS)) { if (log.isDebugEnabled()) { log.debug(format(STARTED_SCANNING_ORG_SPRINGFRAMEWORK, source.getAbsolutePath())); }/*from w w w . j av a2 s . c om*/ try { String contents = readFileToString(source, UTF_8.displayName()); if (isSpringConfigurationAnnotatedClass(contents)) { log.info(format("Skipping verification for Spring configuration class in file '%s'", source.getAbsolutePath())); continue; } // At this point it is clear this is a regular Java class that is not a Spring Configuration class // and just validate we don't have org.springframework in it findMatchesUsingPattern(source, log, contents, patternImport, FOUND_USAGE_OF_ORG_SPRINGFRAMEWORK_IN_IMPORT_AT_LINE); findMatchesUsingPattern(source, log, contents, patternCodeLine, FOUND_USAGE_OF_ORG_SPRINGFRAMEWORK_IN_CODE_FRAGMENT_AT_LINE); } catch (IOException ignore) { log.error(format("Could not process file '%s'", source)); } if (log.isDebugEnabled()) { log.debug(format(FINISHED_SCANNING_ORG_SPRINGFRAMEWORK, source.getAbsolutePath())); } } } }
From source file:io.fabric8.maven.ApplyMojo.java
License:Apache License
public static Route createRouteForService(String routeDomainPostfix, String namespace, Service service, Log log) { Route route = null;/*from w w w.j av a 2s .c o m*/ String id = KubernetesHelper.getName(service); if (Strings.isNotBlank(id) && shouldCreateRouteForService(log, service, id)) { route = new Route(); String routeId = id; KubernetesHelper.setName(route, namespace, routeId); RouteSpec routeSpec = new RouteSpec(); ObjectReference objectRef = new ObjectReference(); objectRef.setName(id); objectRef.setNamespace(namespace); routeSpec.setTo(objectRef); if (!Strings.isNullOrBlank(routeDomainPostfix)) { String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), "."); routeSpec.setHost(host + "." + Strings.stripPrefix(routeDomainPostfix, ".")); } else { routeSpec.setHost(""); } route.setSpec(routeSpec); String json; try { json = KubernetesHelper.toJson(route); } catch (JsonProcessingException e) { json = e.getMessage() + ". object: " + route; } log.debug("Created route: " + json); } return route; }
From source file:io.fabric8.maven.ApplyMojo.java
License:Apache License
/** * Should we try to create a route for the given service? * <p/>//w w w . ja v a2 s . c om * By default lets ignore the kubernetes services and any service which does not expose ports 80 and 443 * * @return true if we should create an OpenShift Route for this service. */ protected static boolean shouldCreateRouteForService(Log log, Service service, String id) { if ("kubernetes".equals(id) || "kubernetes-ro".equals(id)) { return false; } Set<Integer> ports = KubernetesHelper.getPorts(service); log.debug("Service " + id + " has ports: " + ports); if (ports.size() == 1) { return true; } else { log.info("Not generating route for service " + id + " as only single port services are supported. Has ports: " + ports); return false; } }
From source file:io.fabric8.maven.ApplyMojo.java
License:Apache License
public static void loadDependency(Log log, Collection<KubernetesList> kubeConfigs, File file) throws IOException { if (file.isFile()) { log.debug("Loading file " + file); addConfig(kubeConfigs, loadJson(file)); } else {/*from ww w . j ava 2 s.c o m*/ File[] children = file.listFiles(); if (children != null) { for (File child : children) { String name = child.getName().toLowerCase(); if (name.endsWith(".json") || name.endsWith(".yaml")) { loadDependency(log, kubeConfigs, child); } } } } }
From source file:io.fabric8.maven.plugin.AbstractDeployMojo.java
License:Apache License
public static Route createRouteForService(String routeDomainPostfix, String namespace, Service service, Log log) { Route route = null;/*from w w w. j av a 2 s .c om*/ String id = KubernetesHelper.getName(service); if (Strings.isNotBlank(id) && shouldCreateExternalURLForService(log, service, id)) { route = new Route(); String routeId = id; KubernetesHelper.setName(route, namespace, routeId); RouteSpec routeSpec = new RouteSpec(); ObjectReference objectRef = new ObjectReference(); objectRef.setName(id); objectRef.setNamespace(namespace); routeSpec.setTo(objectRef); if (!Strings.isNullOrBlank(routeDomainPostfix)) { String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), "."); routeSpec.setHost(host + "." + Strings.stripPrefix(routeDomainPostfix, ".")); } else { routeSpec.setHost(""); } route.setSpec(routeSpec); String json; try { json = KubernetesHelper.toJson(route); } catch (JsonProcessingException e) { json = e.getMessage() + ". object: " + route; } log.debug("Created route: " + json); } return route; }
From source file:io.fabric8.maven.plugin.AbstractDeployMojo.java
License:Apache License
public static Ingress createIngressForService(String routeDomainPostfix, String namespace, Service service, Log log) { Ingress ingress = null;/*from w ww.ja va2s . com*/ String serviceName = KubernetesHelper.getName(service); ServiceSpec serviceSpec = service.getSpec(); if (serviceSpec != null && Strings.isNotBlank(serviceName) && shouldCreateExternalURLForService(log, service, serviceName)) { String ingressId = serviceName; String host = ""; if (Strings.isNotBlank(routeDomainPostfix)) { host = serviceName + "." + namespace + "." + Strings.stripPrefix(routeDomainPostfix, "."); } List<HTTPIngressPath> paths = new ArrayList<>(); List<ServicePort> ports = serviceSpec.getPorts(); if (ports != null) { for (ServicePort port : ports) { Integer portNumber = port.getPort(); if (portNumber != null) { HTTPIngressPath path = new HTTPIngressPathBuilder().withNewBackend() .withServiceName(serviceName) .withServicePort(createIntOrString(portNumber.intValue())).endBackend().build(); paths.add(path); } } } if (paths.isEmpty()) { return ingress; } ingress = new IngressBuilder().withNewMetadata().withName(ingressId).withNamespace(namespace) .endMetadata().withNewSpec().addNewRule().withHost(host).withNewHttp().withPaths(paths) .endHttp().endRule().endSpec().build(); String json; try { json = KubernetesHelper.toJson(ingress); } catch (JsonProcessingException e) { json = e.getMessage() + ". object: " + ingress; } log.debug("Created ingress: " + json); } return ingress; }