@Override public void onUnknownFile(Document document, Header header) { warn("Unknown file extension: %s", document.getFilePath()); unknownFiles.add(document.getFile()); }
@Override public void onHeaderNotFound(Document document, Header header) { if (skipExistingHeaders) { document.parseHeader(); if (document.headerDetected()) { debug("Existing header in: %s", document.getFilePath()); return; } } warn("Missing header in: %s", document.getFilePath()); missingHeaders.add(document.getFile()); }
public String getFilePath() { return getFile().getPath().replace('\\', '/'); }
@Override public void onHeaderNotFound(Document document, Header header) { document.parseHeader(); if (document.headerDetected()) { if (skipExistingHeaders) { debug("Keeping license header in: %s", document.getFilePath()); return; } document.removeHeader(); } info("Updating license header in: %s", document.getFilePath()); document.updateHeader(header); if (!dryRun) { document.save(); } else { String name = document.getFile().getName() + ".licensed"; File copy = new File(document.getFile().getParentFile(), name); info("Result saved to: %s", copy); document.saveTo(copy); } }
@Override public Properties load(Document d) { Properties properties = new Properties(); for (String key : props.keySet()) { properties.put(key, String.valueOf(props.get(key))); } properties.put("file.name", d.getFile().getName()); return properties; } };
@Override public Properties load(Document d) { Properties properties = new Properties(); for (String key : props.keySet()) { properties.put(key, String.valueOf(props.get(key))); } properties.put("file.name", d.getFile().getName()); return properties; } };
@Override public void onExistingHeader(Document document, Header header) { info("Removing license header from: %s", document.getFile()); remove(document); }
@Override public void onHeaderNotFound(Document document, Header header) { debug("Header was not found in: %s (But keep trying to find another header to remove)", document.getFile()); remove(document); }
if (inceptionYear == null) { throw new RuntimeException("'"+ INCEPTION_YEAR_KEY +"' must have a value for file " + document.getFile().getAbsolutePath()); } catch (NumberFormatException e1) { throw new RuntimeException("'"+ INCEPTION_YEAR_KEY +"' must be an integer ; found = " + inceptionYear +" file: " + document.getFile().getAbsolutePath()); int copyrightEnd = getGitLookup(document.getFile(), properties).getYearOfLastChange(document.getFile()); result.put(COPYRIGHT_LAST_YEAR_KEY, Integer.toString(copyrightEnd)); final String copyrightYears; } catch (Exception e) { throw new RuntimeException("Could not compute the year of the last git commit for file " + document.getFile().getAbsolutePath(), e);
private Map<String, String> mergeProperties(Document document) { // first put systen environment Map<String, String> props = new LinkedHashMap<String, String>(System.getenv()); // then add ${project.XYZ} properties props.put("project.groupId", project.getGroupId()); props.put("project.artifactId", project.getArtifactId()); props.put("project.version", project.getVersion()); props.put("project.name", project.getName()); props.put("project.description", project.getDescription()); props.put("project.inceptionYear", project.getInceptionYear()); props.put("project.url", project.getUrl()); // then add per document properties props.put("file.name", document.getFile().getName()); // we override by properties in the POM if (this.properties != null) { props.putAll(this.properties); } // then we override by java system properties (command-line -D...) for (String key : System.getProperties().stringPropertyNames()) { props.put(key, System.getProperty(key)); } return props; }
if (inceptionYear == null) { throw new RuntimeException("'"+ INCEPTION_YEAR_KEY +"' must have a value for file " + document.getFile().getAbsolutePath()); } catch (NumberFormatException e1) { throw new RuntimeException("'"+ INCEPTION_YEAR_KEY +"' must be an integer ; found = " + inceptionYear +" file: " + document.getFile().getAbsolutePath()); int copyrightEnd = getGitLookup(document.getFile(), properties).getYearOfLastChange(document.getFile()); result.put(COPYRIGHT_LAST_YEAR_KEY, Integer.toString(copyrightEnd)); final String copyrightYears; } catch (Exception e) { throw new RuntimeException("Could not compute the year of the last git commit for file " + document.getFile().getAbsolutePath(), e);
private void remove(Document document) { document.parseHeader(); if (document.headerDetected()) document.removeHeader(); if (!dryRun) { document.save(); } else { String name = document.getFile().getName() + ".licensed"; File copy = new File(document.getFile().getParentFile(), name); info("Result saved to: %s", copy); document.saveTo(copy); } }
public void onHeaderNotFound(Document document, Header header) { document.parseHeader(); if (document.headerDetected()) { if (skipExistingHeaders) { logger.info("Keeping license header in: {}", DocumentFactory.getRelativeFile(basedir, document)); return; } else document.removeHeader(); } logger.lifecycle("Updating license header in: {}", DocumentFactory.getRelativeFile(basedir, document)); document.updateHeader(header); missingHeaders.add(document.getFile()); if (!dryRun) { document.save(); } else { String name = document.getFile().getName() + ".licensed"; File copy = new File(document.getFile().getParentFile(), name); logger.debug("Result saved to: {}", copy); document.saveTo(copy); } }
public Map<String, String> getAdditionalProperties(final AbstractLicenseMojo mojo, Properties currentProperties, Document document) { final Map<String, String> newProperties = new HashMap<String, String>(); final File documentFile = document.getFile();
public void onHeaderNotFound(Document document, Header header) { document.parseHeader(); if (document.headerDetected()) { if (skipExistingHeaders) { logger.info("Keeping license header in: {}", DocumentFactory.getRelativeFile(basedir, document)); return; } else document.removeHeader(); } logger.lifecycle("Updating license header in: {}", DocumentFactory.getRelativeFile(basedir, document)); document.updateHeader(header); missingHeaders.add(document.getFile()); if (!dryRun) { document.save(); } else { String name = document.getFile().getName() + ".licensed"; File copy = new File(document.getFile().getParentFile(), name); logger.debug("Result saved to: {}", copy); document.saveTo(copy); } }
public boolean isMatchForText(Document d, HeaderDefinition headerDefinition, boolean unix, String encoding) throws IOException { String fileHeader = readFirstLines(d.getFile(), getLineCount() + 10, encoding).replaceAll(" *\r?\n", "\n"); String expected = buildForDefinition(headerDefinition, unix); expected = d.mergeProperties(expected); return isMatchForText(expected, fileHeader, headerDefinition, unix); }
@Override public void onHeaderNotFound(Document document, Header header) { document.parseHeader(); if (document.headerDetected() && skipExistingHeaders) { logger.info("Ignoring header in: {}", DocumentFactory.getRelativeFile(basedir, document)); return; } else { logger.lifecycle("Missing header in: {}", DocumentFactory.getRelativeFile(basedir, document)); } missingHeaders.add(document.getFile()); }
@Override public void onHeaderNotFound(Document document, Header header) { document.parseHeader(); if (document.headerDetected() && skipExistingHeaders) { logger.info("Ignoring header in: {}", DocumentFactory.getRelativeFile(basedir, document)); return; } else { logger.lifecycle("Missing header in: {}", DocumentFactory.getRelativeFile(basedir, document)); } missingHeaders.add(document.getFile()); }