Skip to content

Commit

Permalink
Exlude individual files from the builder
Browse files Browse the repository at this point in the history
  • Loading branch information
volosied committed Nov 19, 2024
1 parent 20e4401 commit 012c333
Showing 1 changed file with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ public class MakeComponentsMojo extends AbstractBuilderMojo
*/
private File mainSourceDirectory2;

/**
* Excludes files from the component generation. Must be comma separated.
*
* @parameter
*/
private String[] excludes;

/**
* Execute the Mojo.
*/
Expand All @@ -217,7 +224,20 @@ public void execute() throws MojoExecutionException
File mdFile = new File(buildDirectory, metadataFile);
Model model = IOUtils.loadModel(mdFile);
new Flattener(model).flatten();


for(int i = 0; i < excludes.length; i++){
String str = excludes[i];
getLog().info("Files to be excluded: "+ str);
if(excludes != null){
if(str.contains("**"))
{
// must be reglar expression
str = str.replace("**", ".*");
}
excludes[i] = str;
}
}

Properties cacheInfo = new Properties();
loadCache(cacheInfo);
generateComponents(model, cacheInfo, mdFile.lastModified() );
Expand Down Expand Up @@ -360,7 +380,10 @@ else if (!outFile.exists())
for (Iterator i = sourceDirs.iterator(); i.hasNext();)
{
String srcDir = (String) i.next();
builder.addSourceTree(new File(srcDir));
File dir = new File(srcDir);
//recusively add files to the builder
// allows control to exclude files
addFilesToBuilder(builder,dir);
}

//Init velocity
Expand Down Expand Up @@ -420,6 +443,38 @@ else if (!outFile.exists())
}
}
}

public void addFilesToBuilder(JavaDocBuilder builder, File dir) throws IOException
{
File[] directoryListing = dir.listFiles();
if(directoryListing == null)
{
return;
}
for(int j = 0; j < directoryListing.length; j++)
{
File f = directoryListing[j];
if(f.isDirectory()){
addFilesToBuilder(builder, f);
}
else
{
boolean skip = false;
for(int i = 0; i < excludes.length; i++) {
String currentExclude= excludes[i];
if(currentExclude != null && f.toString().matches(currentExclude))
{
getLog().info("Excluding source from builder: " + f);
skip = true;
break;
}
}
if(!skip){
builder.addSource(f);
}
}
}
}

public boolean canGenerateComponent(ComponentMeta component)
{
Expand Down

0 comments on commit 012c333

Please sign in to comment.