Skip to content

Commit

Permalink
[DROOLS-360] fix incremental compilation for rule templates
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco committed Dec 2, 2013
1 parent 8040e5c commit ee256ec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Expand Up @@ -354,23 +354,25 @@ private void addKBaseFilesToTrg(KieBaseModel kieBase) {
}
}

void copySourceToTarget(String fileName) {
String copySourceToTarget(String fileName) {
if ( !fileName.startsWith(RESOURCES_ROOT) ) {
return;
return null;
}
byte[] bytes = srcMfs.getBytes( fileName );
String trgFileName = fileName.substring( RESOURCES_ROOT.length() - 1 );
String trgFileName = fileName.substring( RESOURCES_ROOT.length() );
if ( bytes != null ) {
FormatConverter formatConverter = FormatsManager.get().getConverterFor( trgFileName );
if ( formatConverter != null ) {
FormatConversionResult result = formatConverter.convert( trgFileName, bytes );
trgMfs.write( result.getConvertedName(), result.getContent(), true );
trgFileName = result.getConvertedName();
trgMfs.write( trgFileName, result.getContent(), true );
} else if ( getResourceType( fileName ) != null ) {
trgMfs.write( trgFileName, bytes, true );
}
} else {
trgMfs.remove( trgFileName );
}
return trgFileName;
}

private ResourceType getResourceType(String fileName) {
Expand Down
Expand Up @@ -61,13 +61,17 @@ KieBuilderSetImpl setFiles(String[] files) {

@Override
public IncrementalResults build() {
Collection<String> filesToBuild = files != null ? asList(files) : kieBuilder.getModifiedResourcesSinceLastMark();
if ( filesToBuild.isEmpty() ) {
Collection<String> srcFiles = files != null ? asList(files) : kieBuilder.getModifiedResourcesSinceLastMark();
Collection<String> filesToBuild = new ArrayList<String>();
if ( srcFiles.isEmpty() ) {
return new IncrementalResultsImpl();
}
kieBuilder.cloneKieModuleForIncrementalCompilation();
for (String file : filesToBuild) {
kieBuilder.copySourceToTarget(file);
for (String file : srcFiles) {
String trgFile = kieBuilder.copySourceToTarget(file);
if (trgFile != null) {
filesToBuild.add(trgFile);
}
}
IncrementalResults result = buildChanges(filesToBuild);
files = null;
Expand Down Expand Up @@ -103,17 +107,13 @@ private IncrementalResults buildChanges(Collection<String> filesToBuild) {
}

for (String file : filesToBuild) {
String resourceName = file.startsWith(KieBuilderImpl.RESOURCES_ROOT) ?
file.substring(KieBuilderImpl.RESOURCES_ROOT.length()) :
file;

if ( wrongResources.contains(resourceName) ) {
if ( wrongResources.contains(file) ) {
modified = true;
} else {
// remove the objects generated by the old Resource
modified = pkgBuilder.removeObjectsGeneratedFromResource(new DummyResource(resourceName)) || modified;
modified = pkgBuilder.removeObjectsGeneratedFromResource(new DummyResource(file)) || modified;
// add the modified Resource
modified = addResource(ckbuilder, kBaseModel, kieModule, resourceName) || modified;
modified = addResource(ckbuilder, kBaseModel, kieModule, file) || modified;
}
}

Expand Down
Expand Up @@ -245,8 +245,9 @@ public void testRuleTemplateIncrementalCompilationAddInvalidUpdateWithValid() th
}

@Test
@Ignore("See https://issues.jboss.org/browse/DROOLS-360")
public void testRuleTemplateIncrementalCompilationAddValidUpdateWithInvalid() throws Exception {
// DROOLS-360

//Valid
// package org.mortgages;
// rule "t1_0"
Expand Down

0 comments on commit ee256ec

Please sign in to comment.