Author: tchemit Date: 2010-04-06 17:13:56 +0200 (Tue, 06 Apr 2010) New Revision: 684 Log: move deprecated code in 1.1.1 + reformar code Modified: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java trunk/src/main/java/org/nuiton/plugin/PluginHelper.java Modified: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2010-04-06 15:03:30 UTC (rev 683) +++ trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2010-04-06 15:13:56 UTC (rev 684) @@ -69,53 +69,57 @@ protected abstract void doAction() throws Exception; @Override - public final void execute() throws MojoExecutionException, MojoFailureException { + public final void execute() throws MojoExecutionException, + MojoFailureException { try { - // check if project packaging is compatible with the mojo + // check if project packaging is compatible with the mojo - boolean canContinue = checkPackaging(); - if (!canContinue) { - getLog().warn("The goal is skip due to packaging '" + getProject().getPackaging() + "'"); - return; - } + boolean canContinue = checkPackaging(); + if (!canContinue) { + getLog().warn("The goal is skip due to packaging '" + + getProject().getPackaging() + "'"); + return; + } - // init the mojo + // init the mojo - try { + try { - init(); + init(); - } catch (Exception e) { - throw new MojoExecutionException("could not init goal " + getClass().getSimpleName() + " for reason : " + e.getMessage(), e); - } + } catch (Exception e) { + throw new MojoExecutionException( + "could not init goal " + getClass().getSimpleName() + + " for reason : " + e.getMessage(), e); + } - // check if mojo can be skipped + // check if mojo can be skipped - canContinue = checkSkip(); - if (!canContinue) { - if (isVerbose() || getLog().isDebugEnabled()) { - getLog().info("Goal will not be executed."); + canContinue = checkSkip(); + if (!canContinue) { + if (isVerbose() || getLog().isDebugEnabled()) { + getLog().info("Goal will not be executed."); + } + return; } - return; - } - // can really execute the mojo + // can really execute the mojo - try { + try { - doAction(); + doAction(); - } catch (Exception e) { - throw new MojoExecutionException("could not execute goal " + getClass().getSimpleName() + " for reason : " + e.getMessage(), e); - } + } catch (Exception e) { + throw new MojoExecutionException( + "could not execute goal " + getClass().getSimpleName() + + " for reason : " + e.getMessage(), e); + } } finally { afterExecute(); } } - /** - * A call back to execute after the {@link #execute()} is done - */ + /** A call back to execute after the {@link #execute()} is done */ protected void afterExecute() { // by default do nothing } @@ -130,11 +134,11 @@ * <p/> * <b>Tip:</b> There is two method to simplify the packaging check : * <p/> - * {@link #acceptPackaging(org.nuiton.plugin.Plugin.Packaging...)} + * {@link #acceptPackaging(Packaging...)} * <p/> * and * <p/> - * {@link #rejectPackaging(org.nuiton.plugin.Plugin.Packaging...)} + * {@link #rejectPackaging(Packaging...)} * * @return {@code true} if can execute the goal for the packaging of the * project, {@code false} otherwise. @@ -192,9 +196,7 @@ return true; } - /** - * @return {@code true} if project is the root execution project - */ + /** @return {@code true} if project is the root execution project */ protected boolean isExecutionRoot() { return getProject().isExecutionRoot(); } @@ -208,7 +210,10 @@ * @param newStartTime the current build start time * @return {@code true} if the goal was already invoked */ - protected boolean checkRunOnceDone(boolean runOnce, boolean onlyForRoot, Date buildStartTime, Date newStartTime) { + protected boolean checkRunOnceDone(boolean runOnce, + boolean onlyForRoot, + Date buildStartTime, + Date newStartTime) { if (!runOnce) { // will run each time @@ -286,7 +291,9 @@ * @param encoding the enconding of the file * @throws IOException if any pb while writing the content into the file */ - public void writeFile(File destFile, String content, String encoding) throws IOException { + public void writeFile(File destFile, + String content, + String encoding) throws IOException { PluginHelper.writeString(destFile, content, encoding); } @@ -384,9 +391,12 @@ * @param updater an updater (will give the mirrored files) * @return the map of mirrored files associated to their files in srcDir */ - protected Map<String, String> getFilesToTreate(String[] includes, String[] excludes, File srcDir, MirroredFileUpdater updater) { + protected Map<String, String> getFilesToTreate(String[] includes, + String[] excludes, + File srcDir, + MirroredFileUpdater updater) { - Map<String, String> result = new java.util.TreeMap<String, String>(); + Map<String, String> result = new TreeMap<String, String>(); DirectoryScanner ds = new DirectoryScanner(); ds.setIncludes(includes); @@ -479,86 +489,68 @@ * @param srcDir the location to include in test compile source roots */ protected void addTestCompileSourceRoots(File srcDir) { - if (!getProject().getTestCompileSourceRoots().contains(srcDir.getPath())) { + if (!getProject().getTestCompileSourceRoots().contains( + srcDir.getPath())) { if (isVerbose()) { - getLog().info("adding test source roots : " + srcDir.getPath()); + getLog().info("adding test source roots : " + + srcDir.getPath()); } getProject().addTestCompileSourceRoot(srcDir.getPath()); } } /** - * Remove a given directory in maven project's test compile source roots (if - * present). + * Remove a given directory in maven project's test compile source roots + * (if present). * * @param srcDir the location to remove from test compile source roots */ protected void removeTestCompileSourceRoots(File srcDir) { - if (getProject().getTestCompileSourceRoots().contains(srcDir.getPath())) { + if (getProject().getTestCompileSourceRoots().contains( + srcDir.getPath())) { if (isVerbose()) { - getLog().info("removing test source roots : " + srcDir.getPath()); + getLog().info("removing test source roots : " + + srcDir.getPath()); } getProject().getTestCompileSourceRoots().remove(srcDir.getPath()); } } /** - * Add a new resource location to the maven project (in not already present). + * Add a new resource location to the maven project + * (in not already present). * * @param dir the new resource location to add * @param includes files to include * @since 1.1.1 */ protected void addResourceDir(File dir, String... includes) { - boolean added = PluginHelper.addResourceDir(dir, getProject(), includes); + boolean added = PluginHelper.addResourceDir(dir, getProject(), + includes); if (added && isVerbose()) { - getLog().info("add resource " + dir + " with includes " + Arrays.toString(includes)); + getLog().info("add resource " + dir + " with includes " + + Arrays.toString(includes)); } } /** - * Add a new test resource location to the maven project (in not already present). + * Add a new test resource location to the maven project + * (in not already present). * * @param dir the new resource location to add * @param includes files to include * @since 1.1.1 */ protected void addTestResourceDir(File dir, String... includes) { - boolean added = PluginHelper.addTestResourceDir(dir, getProject(), includes); + boolean added = PluginHelper.addTestResourceDir( + dir, getProject(), includes); if (added && isVerbose()) { - getLog().info("add test resource " + dir + " with includes " + Arrays.toString(includes)); + getLog().info("add test resource " + dir + " with includes " + + Arrays.toString(includes)); } } /** - * Add a new resource location to the maven project (in not already present). - * - * @param dir the new resource location to add - * @deprecated since 1.1.1, prefer use the method {@link #addResourceDir(java.io.File, String...)} - */ - @Deprecated - protected void addResourceDir(String dir) { - boolean added = PluginHelper.addResourceDir(dir, getProject()); - if (added) { - getLog().info("add resource " + dir); - } - } - - /** - * Add a new test resource location to the maven project (in not already present). - * - * @param dir the new resource location to add - * @deprecated since 1.1.1, prefer use the method {@link #addTestResourceDir(java.io.File, String...)} - */ - @Deprecated - protected void addTestResourceDir(String dir) { - boolean added = PluginHelper.addTestResourceDir(dir, getProject()); - if (added) { - getLog().info("add test resource " + dir); - } - } - - /** * Create the directory if necessary. * * @param dir the directory to create if not already existing @@ -594,16 +586,16 @@ PluginHelper.deleteFile(file); } - /** + /** * Rename the given file to the destination one. * - * @param file the file to rename + * @param file the file to rename * @param destination the destination of the file * @throws IOException if could not delete the file * @since 1.2.0 */ - protected void renameFile(File file,File destination) throws IOException { - PluginHelper.renameFile(file,destination); + protected void renameFile(File file, File destination) throws IOException { + PluginHelper.renameFile(file, destination); } @@ -616,7 +608,7 @@ } /** - * Backups the given file using the {@link #getBackupFile(java.io.File)} as + * Backups the given file using the {@link #getBackupFile(File)} as * destination file. * * @param f the file to backup @@ -641,7 +633,14 @@ * @throws MalformedURLException if an url was not correct */ @SuppressWarnings({"unchecked"}) - protected URLClassLoader initClassLoader(MavenProject project, File src, boolean addSourcesToClassPath, boolean testPhase, boolean addResourcesToClassPath, boolean addCompileClassPath, boolean addProjectClassPath) throws MalformedURLException { + protected URLClassLoader initClassLoader( + MavenProject project, + File src, + boolean addSourcesToClassPath, + boolean testPhase, + boolean addResourcesToClassPath, + boolean addCompileClassPath, + boolean addProjectClassPath) throws MalformedURLException { URLClassLoader loader; if (project != null) { @@ -657,19 +656,25 @@ addDirectoryToUrlsList(new File(source), lUrls, dones); } if (testPhase) { - for (Object source : project.getTestCompileSourceRoots()) { - addDirectoryToUrlsList(new File(source.toString()), lUrls, dones); + for (Object source : + project.getTestCompileSourceRoots()) { + addDirectoryToUrlsList( + new File(source.toString()), lUrls, dones); } } } if (addResourcesToClassPath) { for (Object source : project.getResources()) { Resource r = (Resource) source; - addDirectoryToUrlsList(new File(r.getDirectory()), lUrls, dones); + addDirectoryToUrlsList( + new File(r.getDirectory()), lUrls, dones); } } if (testPhase && addCompileClassPath) { - addDirectoryToUrlsList(new File(project.getBuild().getOutputDirectory()), lUrls, dones); + addDirectoryToUrlsList( + new File(project.getBuild().getOutputDirectory()), + lUrls, + dones); } if (src != null) { addDirectoryToUrlsList(src, lUrls, dones); @@ -684,10 +689,15 @@ } } - result = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader()); + result = new URLClassLoader( + lUrls.toArray(new URL[lUrls.size()]), + getClass().getClassLoader() + ); } catch (IOException e) { - throw new RuntimeException("Can't create ClassLoader for reason " + e.getMessage(), e); + throw new RuntimeException( + "Can't create ClassLoader for reason " + + e.getMessage(), e); } loader = result; } else { @@ -695,7 +705,8 @@ if (addSourcesToClassPath) { lUrls.add(src.toURI().toURL()); } - loader = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader()); + loader = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), + getClass().getClassLoader()); } if (isVerbose()) { for (URL entry : loader.getURLs()) { @@ -709,7 +720,7 @@ * Add the given {@code directory} in {@code urls} if not already included. * <p/> * <b>Note:</b> We use a extra list to store file string representation, since - * we do NOT want any url resolution and the {@link URL#equals(java.lang.Object)} is + * we do NOT want any url resolution and the {@link URL#equals(Object)} is * doing some... * * @param directory the directory to insert in {@code urls} @@ -718,17 +729,21 @@ * @throws MalformedURLException if pb while converting file to url * @since 1.1.0 */ - protected void addDirectoryToUrlsList(File directory, List<URL> urls, Set<String> done) throws MalformedURLException { - // do the comparaison on a String to avoid url to be resolved (in URL.equals method) + protected void addDirectoryToUrlsList( + File directory, + List<URL> urls, + Set<String> done) throws MalformedURLException { + // do the comparaison on a String to avoid url to be resolved + // (in URL.equals method) addUrlToUrlsList(directory.toURI().toURL(), urls, done); } /** * Add the given {@code url} in {@code urls} if not already included. * <p/> - * <b>Note:</b> We use a extra list to store file string representation, since - * we do NOT want any url resolution and the {@link URL#equals(java.lang.Object)} is - * doing some.. + * <b>Note:</b> We use a extra list to store file string representation, + * since we do NOT want any url resolution and the + * {@link URL#equals(Object)} is doing some.. * * @param url the url to insert in {@code urls} * @param urls list of urls @@ -736,7 +751,8 @@ * @since 1.1.0 */ protected void addUrlToUrlsList(URL url, List<URL> urls, Set<String> done) { - // do the comparaison on a String to avoid url to be resolved (in URL.equals method) + // do the comparaison on a String to avoid url to be resolved + // (in URL.equals method) String u = url.toString(); if (!done.contains(u)) { done.add(u); @@ -749,7 +765,8 @@ * * @param f the required resource file. * @return the url of the resource - * @throws IOException for any error while looking up for the url of the resources + * @throws IOException for any error while looking up for the url of + * the resources */ protected URL getTemplate(File f) throws IOException { URL r = null; @@ -765,7 +782,8 @@ * Check that the given resource exists in a simple fs file or in the classPath. * * @param f the required resource file. - * @throws IOException for any error while looking up for the resources content. + * @throws IOException for any error while looking up for the resources + * content. */ protected void checkResource(File f) throws IOException { if (!f.exists()) { Modified: trunk/src/main/java/org/nuiton/plugin/PluginHelper.java =================================================================== --- trunk/src/main/java/org/nuiton/plugin/PluginHelper.java 2010-04-06 15:03:30 UTC (rev 683) +++ trunk/src/main/java/org/nuiton/plugin/PluginHelper.java 2010-04-06 15:13:56 UTC (rev 684) @@ -82,7 +82,7 @@ if (!type.isAssignableFrom(o.getClass())) { throw new IllegalArgumentException( "can not cast List with object of type " + - o.getClass() + " to " + type + " type!"); + o.getClass() + " to " + type + " type!"); } } return (List<O>) list; @@ -120,8 +120,7 @@ tmp *= sign; String result; - result = MessageFormat.format("{0,number,0.###}{1}", tmp, - unites[i]); + result = MessageFormat.format("{0,number,0.###}{1}", tmp, unites[i]); return result; } @@ -276,69 +275,6 @@ } /** - * @param newresourceDir the new resource directory to add - * @param project the maven project to modifiy - * @return {@code true} if resources was added - * @deprecated since 1.1.1, prefer use the {@link #addResourceDir(File, - * MavenProject, String...)} - */ - @Deprecated - public static boolean addResourceDir(String newresourceDir, - MavenProject project) { - List<?> resources = project.getResources(); - boolean added = addResourceDir(newresourceDir, project, resources); - return added; - } - - /** - * @param newresourceDir the new resource directory to add - * @param project the maven project to modifiy - * @return {@code true} if resources was added - * @deprecated since 1.1.1, prefer use the {@link #addTestResourceDir(File, - * MavenProject, String...)} - */ - @Deprecated - public static boolean addTestResourceDir(String newresourceDir, - MavenProject project) { - List<?> resources = project.getTestResources(); - boolean added = addResourceDir(newresourceDir, project, resources); - return added; - } - - /** - * @param newresourceDir the new resource directory to add - * @param project the maven project to modifiy - * @param resources the known resources for the maven project - * @return {@code true} if resources was added - * @deprecated since 1.1.1, prefer use the {@link #addResourceDir(File, - * MavenProject, List, String...)} - */ - @Deprecated - public static boolean addResourceDir(String newresourceDir, - MavenProject project, - List<?> resources) { - boolean shouldAdd = true; - for (Object o : resources) { - Resource r = (Resource) o; - if (!r.getDirectory().equals(newresourceDir)) { - continue; - } - r.addInclude("**/*.properties"); - r.addInclude("**/*.txt"); - shouldAdd = false; - break; - } - if (shouldAdd) { - Resource r = new Resource(); - r.setDirectory(newresourceDir); - r.addInclude("**/*.properties"); - r.addInclude("**/*.txt"); - project.addResource(r); - } - return shouldAdd; - } - - /** * Cretae the directory (and his parents) if necessary. * * @param dir the directory to create if not exisiting @@ -414,7 +350,7 @@ if (!b) { throw new IOException( "could not changed lastModified [" + lastModified + - "] for " + file); + "] for " + file); } } @@ -670,6 +606,15 @@ return result.toArray(new URL[result.size()]); } + /** + * suffix a given {@code baseUrl} with the given {@code suffix} + * + * @param baseUrl base url to use + * @param suffix suffix to add + * @return the new url + * @throws IllegalArgumentException if malformed url. + * @since 1.2.3 + */ public static URL getUrl(URL baseUrl, String suffix) throws IllegalArgumentException { String url = baseUrl.toString() + "/" + suffix;
participants (1)
-
tchemit@users.nuiton.org