Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2010 eXo Platform SAS.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.wikbook.maven;
 
 
 import java.io.File;
 import java.net.URL;
 import java.util.List;
 import java.util.Set;

Author(s):
Julien Viet
Version:
$Revision$
Goal:
transform
Phase:
compile
RequiresDependencyResolution:
 
 public class WikBookMojo extends AbstractMojo implements WikletContext
 {

   
The source directory.

Parameter:
 
    private File sourceDirectory;

   
The source file name.

Parameter:
 
    private String sourceFileName;

   
The syntax id.

Parameter:
 
    private String syntaxId;

   
The destination directory.

Parameter:
 
    private File destinationDirectory;

   
The destination file name.

Parameter:
 
    private String destinationFileName;

   
Turn on/off code highlighting

Parameter:
default-value="true"
 
   private boolean highlightCode;

   
Turn on/off code doctype generation of the DocBook document.

Parameter:
default-value="true"
   private boolean emitDoctype;

   
INTERNAL : The representation of the maven execution.

Parameter:
expression="${session}"
Required:
Readonly:
   private MavenSession session;

   

Parameter:
expression="${plugin.artifacts}"
Required:
Readonly:
   private List pluginArtifacts;

   
The source directories containing the sources to be compiled.

Parameter:
default-value="${project.compileSourceRoots}"
Required:
Readonly:
   private List<StringcompileSourceRoots;

   
Project classpath.

Parameter:
default-value="${project.compileClasspathElements}"
Required:
Readonly:
   private List<StringcompileClasspathElements;

   
The source directories containing the sources to be compiled.

Parameter:
default-value="${project.testCompileSourceRoots}"
Required:
Readonly:
   private List<StringtestCompileSourceRoots;

   
Project classpath.

Parameter:
default-value="${project.testClasspathElements}"
Required:
Readonly:
   public void execute() throws MojoExecutionExceptionMojoFailureException
   {
      File src = new File();
      if (!src.exists())
      {
         throw new MojoFailureException("Source file " + src.getAbsolutePath() + " does not exist");
      }
      if (!src.isFile())
      {
         throw new MojoFailureException("Source file " + src.getAbsolutePath() + " is not a file");
      }
      //
      if (.exists())
      {
         if (!.isDirectory())
         {
            throw new MojoFailureException("Destination directory " + .getAbsolutePath() + " is not a directory");
         }
      }
      else
      {
         if (!.mkdirs())
         {
            throw new MojoFailureException("Could not create destination directory " + .getAbsolutePath());
         }
      }
      //
      WikletConverter converter;
      try
      {
         converter = new WikletConverter(this);
      }
      catch (Exception e)
      {
         throw new MojoFailureException(""e);
      }
      //
      converter.setEmitDoctype();
      converter.setSyntaxId();
      //
      File destination = new File();
      //
      FileWriter out = null;
      try
      {
         out = new FileWriter(destination);
         StreamResult result = new StreamResult(out);
         converter.convert(result);
      }
      catch (Exception e)
      {
         MojoFailureException mfe = new MojoFailureException("Could not create destination file " + e.getMessage());
         mfe.initCause(e);
         throw mfe;
      }
      finally
      {
         if (out != null)
         {
            try
            {
               out.close();
            }
            catch (IOException e)
            {
               e.printStackTrace();
            }
         }
      }
   }
   public boolean getHighlightCode()
   {
      return ;
   }
   public List<PersonfindPersonsByRole(String roleName)
   {
      ArrayList<Personps = new ArrayList<Person>();
      MavenProject project = .getCurrentProject();
      for (Iterator<?> i = project.getDevelopers().iterator();i.hasNext();)
      {
         Developer developer = (Developer)i.next();
         if (developer.getRoles().contains(roleName))
         {
            String firstName = null;
            String lastName = null;
            if (developer.getName() != null)
            {
               String[] names = developer.getName().trim().split("\\s+");
               if (names.length > 0)
               {
                  firstName = names[0];
               }
               if (names.length > 1)
               {
                  firstName = names[1];
               }
            }
            Person p = new Person(firstNamelastNamedeveloper.getEmail(), developer.getOrganization(), new HashSet<String>(developer.getRoles()));
            ps.add(p);
         }
      }
      return ps;
   }
   public List<URLresolveResources(ResourceType typeString idthrows IOException
   {
      switch (type)
      {
         case :
            File f = new File(id);
            if (f.exists() && f.isFile())
            {
               return Arrays.asList(f.toURI().toURL());
            }
            break;
         case :
            LinkedHashSet<URLurls = new LinkedHashSet<URL>();
            //
            List<Stringdirs = new ArrayList<String>();
            dirs.addAll();
            dirs.addAll();
            dirs.addAll();
            dirs.addAll();
            //
            for (String elt : dirs)
            {
               File eltFile = new File(elt);
               if (eltFile.exists())
               {
                  urls.add(eltFile.toURI().toURL());
               }
            }
            //
            for (Artifact artifact : (Set<Artifact>).getCurrentProject().getDependencyArtifacts())
            {
               urls.add(artifact.getFile().toURI().toURL());
            }
            //
            ClassLoader cl = new URLClassLoader(urls.toArray(new URL[urls.size()]), ClassLoader.getSystemClassLoader());
            Enumeration<URLfound = cl.getResources(id);
            ArrayList<URLbilto = new ArrayList<URL>();
            while (found.hasMoreElements())
            {
               bilto.add(found.nextElement());
            }
            //
            return bilto;
      }
      return null;
   }
   public URL resolveResource(ResourceType typeString idthrows IOException
   {
      List<URLfound = resolveResources(typeid);
      return found.isEmpty() ? null : found.get(0);
   }
   public String getProperty(String propertyName)
   {
      Properties properties = .getCurrentProject().getProperties();
      return properties.getProperty(propertyName);
   }
New to GrepCode? Check out our FAQ X