/** Returns the mapper to use based on nested elements or the flatten attribute. */ private FileNameMapper getMapper() { FileNameMapper mapper; if (mapperElement != null) { mapper = mapperElement.getImplementation(); } else { mapper = new IdentityMapper(); } return mapper; }
protected void checkConfiguration() { super.checkConfiguration(); if (mapperElement == null) { throw new BuildException("no mapper specified", location); } if (destDir == null) { throw new BuildException("no dest attribute specified", location); } mapper = mapperElement.getImplementation(); }
/** * Checks to make sure all settings are kosher. In this case, it means that the targetdir * attribute has been set and we have a mapper. */ public void verifySettings() { if (targetdir == null) { setError("The targetdir attribute is required."); } if (mapperElement == null) { map = new IdentityMapper(); } else { map = mapperElement.getImplementation(); } if (map == null) { setError("Could not set <mapper> element."); } }
/** * Executes the task. * * @throws BuildException is there is a problem in the task execution. */ public void execute() throws BuildException { // first off, make sure that we've got a from and to extension if (fromExtension == null || toExtension == null || srcDir == null) { throw new BuildException( "srcDir, fromExtension and toExtension " + "attributes must be set!"); } log("DEPRECATED - The renameext task is deprecated. Use move instead.", Project.MSG_WARN); log("Replace this with:", Project.MSG_INFO); log("<move todir=\"" + srcDir + "\" overwrite=\"" + replace + "\">", Project.MSG_INFO); log(" <fileset dir=\"" + srcDir + "\" />", Project.MSG_INFO); log(" <mapper type=\"glob\"", Project.MSG_INFO); log(" from=\"*" + fromExtension + "\"", Project.MSG_INFO); log(" to=\"*" + toExtension + "\" />", Project.MSG_INFO); log("</move>", Project.MSG_INFO); log("using the same patterns on <fileset> as you\'ve used here", Project.MSG_INFO); Move move = new Move(); move.bindToOwner(this); move.setOwningTarget(getOwningTarget()); move.setTaskName(getTaskName()); move.setLocation(getLocation()); move.setTodir(srcDir); move.setOverwrite(replace); fileset.setDir(srcDir); move.addFileset(fileset); Mapper me = move.createMapper(); me.setType(globType); me.setFrom("*" + fromExtension); me.setTo("*" + toExtension); move.execute(); }
public String toString() { StringBuffer buf = new StringBuffer("{presentselector targetdir: "); if (targetdir == null) { buf.append("NOT YET SET"); } else { buf.append(targetdir.getName()); } buf.append(" present: "); if (destmustexist) { buf.append("both"); } else { buf.append("srconly"); } if (map != null) { buf.append(map.toString()); } else if (mapperElement != null) { buf.append(mapperElement.toString()); } buf.append("}"); return buf.toString(); }
@Override public void execute() throws BuildException { if (name == null) throw new BuildException("name property have to be set", getLocation()); String value = ""; String prefix = ""; for (String property : properties) { String[] props; if (mapper != null) { props = mapper.getImplementation().mapFileName(property); } else { props = new String[] {property}; } for (String p : props) { String oneValue = getProject().getProperty(p); if (oneValue != null && oneValue.length() > 0) { value += prefix + oneValue; prefix = ","; } } } getProject().setNewProperty(name, value); }
@Override public void execute() throws BuildException { DirUtil.checkDir(dir1, "dir1", false); // $NON-NLS-1$ DirUtil.checkDir(dir2, "dir2", false); // $NON-NLS-1$ if (mapper == null) { add(new IdentityMapper()); } try { DirectoryScanner ds = super.getDirectoryScanner(dir1); // use default includes if unset: if (!getImplicitFileSet().hasPatterns()) ds.setIncludes(new String[] {"**/*.properties"}); // $NON-NLS-1$ ds.scan(); String[] files = ds.getIncludedFiles(); for (int i = 0; i < files.length; i++) { String prop1Filename = files[i]; File prop1File = new File(dir1, prop1Filename); String[] outFile = mapper.getImplementation().mapFileName(prop1Filename); if (outFile == null || outFile.length == 0) { if (failOnNull) throw new BuildException("Input filename " + prop1File + " mapped to null"); log("Skipping " + prop1File + ": filename mapped to null", Project.MSG_VERBOSE); continue; } String prop2Filename = outFile[0]; // FIXME support multiple output mappings? File prop2File = new File(dir2, prop2Filename); Properties props1 = new Properties(); InputStream in1 = new FileInputStream(prop1File); try { props1.load(in1); Properties props2 = new Properties(); InputStream in2 = new FileInputStream(prop2File); try { props2.load(in2); int errorCount = 0; StringBuilder errors = new StringBuilder(); errors.append(prop1File.getPath() + " is different from " + prop2File.getPath() + ": "); errors.append(System.getProperty("line.separator")); // $NON-NLS-1$ for (Map.Entry<Object, Object> entry : props1.entrySet()) { String propName = (String) entry.getKey(); String prop1Val = (String) entry.getValue(); String prop2Val = (String) props2.remove(propName); if (!equivalent(prop1Val, prop2Val)) { ++errorCount; recordError( errors, propName + " -> {" + prop1Val + ", " + prop2Val + "}"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ } } if (!props2.isEmpty()) { ++errorCount; String message = "second file contains extra keys: " + props2.keySet(); recordError(errors, message); } if (errorCount != 0) throw new BuildException(errors.toString()); } finally { in2.close(); } } finally { in1.close(); } } log("Verified .properties files in " + dir1 + " against " + dir2, Project.MSG_VERBOSE); } catch (Exception e) { throw new BuildException(e); } }
public void add(FileNameMapper filenameMapper) { Mapper mapper = new Mapper(getProject()); mapper.add(filenameMapper); addMapper(mapper); }
/** * Add a Mapper * * @param mapper the mapper to add */ public void addConfiguredMapper(Mapper mapper) { add(mapper.getImplementation()); }