Skip to content

Commit

Permalink
jcr2vfs: fix few dozens of errors/warnings reported by FindBugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Siroky committed Mar 4, 2014
1 parent fe0fdb1 commit 94ace31
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public boolean parseArgs( String[] args ) {
}

public void migrateAll() {
System.out.format( "Migration started. Reading from inputJcrRepository ({%s}).\n",
System.out.format( "Migration started. Reading from inputJcrRepository ({%s}).%n",
migrationConfig.getInputJcrRepository().getAbsolutePath() );

try {
Expand Down Expand Up @@ -99,13 +99,13 @@ public void migrateAll() {
}

if ( Jcr2VfsMigrationApp.hasWarnings ) {
System.out.format( "Migration ended with warnings. Written into outputVfsRepository ({%s}).\n",
System.out.format( "Migration ended with warnings. Written into outputVfsRepository ({%s}).%n",
migrationConfig.getOutputVfsRepository().getAbsolutePath() );
} else if ( Jcr2VfsMigrationApp.hasErrors ) {
System.out.format( "Migration ended with errors. Written into outputVfsRepository ({%s}).\n",
System.out.format( "Migration ended with errors. Written into outputVfsRepository ({%s}).%n",
migrationConfig.getOutputVfsRepository().getAbsolutePath() );
} else {
System.out.format( "Migration ended. Written into outputVfsRepository ({%s}).\n",
System.out.format( "Migration ended. Written into outputVfsRepository ({%s}).%n",
migrationConfig.getOutputVfsRepository().getAbsolutePath() );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class MigrationConfig {

private static String DEFAULT_MIGRATION_FILE_SYSTEM = "guvnor-jcr2vfs-migration";

public static String formatstr = "runMigration [options...]";
public static final String formatstr = "runMigration [options...]";

private File inputJcrRepository;
private File outputVfsRepository;
Expand Down Expand Up @@ -130,7 +130,11 @@ private boolean parseArgOutputVfsRepository( CommandLine commandLine,
System.out.println( "The outputVfsRepository (" + outputVfsRepository + ") has issues: " + e );
return false;
}
outputVfsRepository.mkdirs();
try {
FileUtils.forceMkdir(outputVfsRepository);
} catch (IOException e) {
throw new RuntimeException("Can't create the output VFS directory!", e);
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void migrateAll() {
for (AssetPageRow row : response.getPageRowList()) {
AssetItem assetItemJCR = rulesRepository.loadAssetByUUID(row.getUuid());
assetName =assetItemJCR.getName();
System.out.format(" Asset [%s] with format [%s] is being migrated... \n",
System.out.format(" Asset [%s] with format [%s] is being migrated... %n",
assetItemJCR.getName(), assetItemJCR.getFormat());
//TODO: Git wont check in a version if the file is not changed in this version. Eg, the version 3 of "testFunction.function"
//We need to find a way to force a git check in. Otherwise migrated version history is not consistent with the version history in old Guvnor.
Expand All @@ -156,8 +156,7 @@ public void migrateAll() {
//control, its just the current content on jcr node) is equal to the latest version that had been checked in.
//Eg, when we import mortgage example, we just dump the mortgage package to a jcr node, no version check in.
migrate(jcrModule, assetItemJCR, null);
System.out.format(" Done.\n",
assetItemJCR.getName(), assetItemJCR.getFormat());
System.out.format(" Done.%n");
}
} catch (SerializationException e) {
System.out.println("SerializationException migrating asset: " + assetName +" from module: "+jcrModule.getName());
Expand Down Expand Up @@ -232,7 +231,7 @@ private Path migrate(Module jcrModule, AssetItem jcrAssetItem, Path previousVers
//Ignore
} else { //another format is migrated as a attachmentAsset
Jcr2VfsMigrationApp.hasWarnings = true;
System.out.format(" WARNING: asset [%s] with format[%s] is not a known format by migration tool. It will be migrated as attachmentAsset \n", jcrAssetItem.getName(), jcrAssetItem.getFormat());
System.out.format(" WARNING: asset [%s] with format[%s] is not a known format by migration tool. It will be migrated as attachmentAsset %n", jcrAssetItem.getName(), jcrAssetItem.getFormat());
return attachementAssetMigrater.migrate(jcrModule, jcrAssetItem, previousVersionPath);
}

Expand Down Expand Up @@ -267,7 +266,7 @@ public int compare(TableDataRow r1,
logger.debug(" Asset ({}) with format ({}) migrated: version [{}], comment[{}], lastModified[{}]",
historicalAssetJCR.getName(), historicalAssetJCR.getFormat(), historicalAssetJCR.getVersionNumber(), historicalAssetJCR.getCheckinComment(), historicalAssetJCR.getLastModified().getTime());
}
} catch (Exception e){
} catch (RuntimeException e){
System.out.println("Exception migrating assetHistory at version: "+currentVersionAssetName +" from module: "+jcrModule.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void migrateAll() {
Module[] jcrModules = jcrRepositoryModuleService.listModules();
for ( Module jcrModule : jcrModules ) {
migrate( jcrModule );
System.out.format( " Module [%s] migrated. \n", jcrModule.getName() );
System.out.format( " Module [%s] migrated. %n", jcrModule.getName() );
}

Module globalModule = jcrRepositoryModuleService.loadGlobalModule();
Expand All @@ -47,14 +47,17 @@ private void migrate( Module jcrModule ) {
//Set up project structure:
jcrModule.setName(migrationPathManager.normalizePackageName(jcrModule.getName()));

String [] nameSplit = jcrModule.getName().split("\\.");
String groupId=nameSplit[0];
String artifactId=nameSplit[nameSplit.length-1];
String[] nameSplit = jcrModule.getName().split("\\.");

for(int i =1 ;i< nameSplit.length-1;i++){
groupId +="."+ nameSplit[i];
StringBuilder groupIdBuilder = new StringBuilder();
groupIdBuilder.append(nameSplit[0]);
for (int i = 1; i < nameSplit.length - 1; i++) {
groupIdBuilder.append(".");
groupIdBuilder.append(nameSplit[i]);
}

String groupId = groupIdBuilder.toString();
String artifactId = nameSplit[nameSplit.length - 1];
GAV gav = new GAV(groupId,
artifactId,
"0.0.1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.Charset;
import javax.inject.Inject;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand All @@ -16,6 +17,7 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import com.google.common.base.Charsets;
import org.apache.commons.httpclient.util.URIUtil;
import org.drools.workbench.models.commons.backend.imports.ImportsParser;
import org.drools.workbench.models.commons.backend.packages.PackageNameParser;
Expand Down Expand Up @@ -63,7 +65,7 @@ public String assertPackageNameXML( final String xml,
try {
DocumentBuilder dombuilder = domfac.newDocumentBuilder();

Document doc = dombuilder.parse( new ByteArrayInputStream( xml.getBytes() ) );
Document doc = dombuilder.parse( new ByteArrayInputStream( xml.getBytes( Charsets.UTF_8 ) ) );

if ( doc.getElementsByTagName( "packageName" ).getLength() != 0 ) {
return xml;
Expand Down Expand Up @@ -146,7 +148,7 @@ public String assertPackageImportXML( final String xml,

try {
DocumentBuilder dombuilder = domfac.newDocumentBuilder();
Document doc = dombuilder.parse( new ByteArrayInputStream( xml.getBytes() ) );
Document doc = dombuilder.parse( new ByteArrayInputStream( xml.getBytes( Charsets.UTF_8 ) ) );

if ( doc.getElementsByTagName( "imports" ).getLength() != 0 ) {
return xml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@ public class AttachementAssetMigrater extends BaseAssetMigrater {

protected static final Logger logger = LoggerFactory.getLogger( AttachementAssetMigrater.class );

@Inject
protected RepositoryAssetService jcrRepositoryAssetService;

@Inject
@Named("ioStrategy")
private IOService ioService;

@Inject
protected MigrationPathManager migrationPathManager;

public Path migrate( Module jcrModule,
AssetItem jcrAssetItem,
Path previousVersionPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,22 @@ public String getExtendedRuleFromCategoryRules(Module jcrModule, AssetItem jcrAs
}
// Now iterate by the asset categories, and construct the extendRuleExpression if the category is in catRuleHashMap
List<org.drools.repository.CategoryItem> assetCategories = jcrAssetItem.getCategories();
String extendCategories = "";
StringBuilder extendCategoriesBuilder = new StringBuilder();
int i = 0;
for (CategoryItem categoryItem : assetCategories) {
ruleName = (String) catRuleHashMap.get(categoryItem.getName());
if (ruleName != null) {
if (i != 0) extendCategories += ", ";
if (i != 0) extendCategoriesBuilder.append(", ");
// prepared for multiple hierarchy,
// but in the old platform the multiple hierarchy was not supported
extendCategories += ruleDelimiter + ruleName + ruleDelimiter;
extendCategoriesBuilder.append(ruleDelimiter);
extendCategoriesBuilder.append(ruleName);
extendCategoriesBuilder.append(ruleDelimiter);
i++;
}
}
// extendCategories has Delimiter+ rule1Name + Delimiter + added by the packageCategoryRules definition
return extendCategories;
return extendCategoriesBuilder.toString();
}

/**
Expand All @@ -136,11 +138,12 @@ public String getExtendExpression(Module jcrModule, AssetItem jcrAssetItem, Stri
} else {
contentSplit[0] += "," + extendedRules;
}
String str="";
for (String s:contentSplit){
str+=s+"\n";
StringBuilder contentWithExtendsBuilder = new StringBuilder();
for (String s : contentSplit) {
contentWithExtendsBuilder.append(s);
contentWithExtendsBuilder.append("\n");
}
return str;
return contentWithExtendsBuilder.toString();
}
return content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ public class FactModelsMigrater extends BaseAssetMigrater {

protected static final Logger logger = LoggerFactory.getLogger(FactModelsMigrater.class);

@Inject
protected RepositoryAssetService jcrRepositoryAssetService;

@Inject
protected MigrationPathManager migrationPathManager;

@Inject
@Named("ioStrategy")
private IOService ioService;
Expand Down Expand Up @@ -149,12 +143,6 @@ private AnnotationDefinitionTO getPositionAnnotationDefinition() {
//from the full JCR Module name (assuming they're formatted "projectName.subModule1.subModule2" etc
private String getPackageName(Module jcrModule) {
String packageName = jcrModule.getName();
int dotIndex = packageName.indexOf( "." );
// if(dotIndex==-1) {
//packageName="";
// } else {
// packageName = packageName.substring( dotIndex +1 );
// }
return packageName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,13 @@ public class GlobalMigrater extends BaseAssetMigrater {
protected static final Logger logger = LoggerFactory.getLogger( GlobalMigrater.class );
private static final String GLOBAL_KEYWORD = "global ";

@Inject
protected RepositoryAssetService jcrRepositoryAssetService;

@Inject
private Paths paths;

@Inject
@Named("ioStrategy")
private IOService ioService;

@Inject
protected MigrationPathManager migrationPathManager;

@Inject
private PackageHeaderInfo packageHeaderInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,9 @@ public class GuidedDecisionTableMigrater extends BaseAssetMigrater {

protected static final Logger logger = LoggerFactory.getLogger( GuidedDecisionTableMigrater.class );

@Inject
protected RepositoryAssetService jcrRepositoryAssetService;

@Inject
protected GuidedRuleEditorService guidedRuleEditorService;

@Inject
protected MigrationPathManager migrationPathManager;

@Inject
@Named("ioStrategy")
private IOService ioService;
Expand Down Expand Up @@ -72,10 +66,6 @@ public Path migrate( Module jcrModule,

String content = jcrAssetItem.getContent();

/* while(content.indexOf("<auditLog>") > -1) {
content = content.replaceAll(content.substring(content.indexOf("<auditLog>"), content.indexOf("</auditLog>")+11), "");
}
*/
content = content.replaceAll( "org.drools.guvnor.client.modeldriven.dt52.Pattern52",
"Pattern52" );

Expand All @@ -92,7 +82,7 @@ public Path migrate( Module jcrModule,

}
final String requiredPackageName = pkName;
if ( requiredPackageName != null || !"".equals( requiredPackageName ) ) {
if ( requiredPackageName != null && !"".equals( requiredPackageName ) ) {
model.setPackageName( requiredPackageName );
}
model.setParentName(getExtendedRuleFromCategoryRules(jcrModule,jcrAssetItem,""));
Expand All @@ -107,22 +97,13 @@ public Path migrate( Module jcrModule,

String sourceContent = GuidedDTXMLPersistence.getInstance().marshal( model );

/* GuidedDTContentHandler h = new GuidedDTContentHandler();
String sourceContent = h.getRawDRL(jcrAssetItem);*/

//String sourceContent = jcrAssetItem.getContent();

//String sourceContentWithPackage = packageImportHelper.assertPackageNameXML(sourceContent, path);
//sourceContentWithPackage = packageImportHelper.assertPackageImportXML(sourceContentWithPackage, path);

ioService.write( nioPath,
sourceContent,
migrateMetaData(jcrModule, jcrAssetItem),
new CommentedOption( jcrAssetItem.getLastContributor(),
null,
jcrAssetItem.getCheckinComment(),
jcrAssetItem.getLastModified().getTime() ) );

return path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,13 @@ public class GuidedEditorMigrater extends BaseAssetMigrater {

protected static final Logger logger = LoggerFactory.getLogger( GuidedEditorMigrater.class );

@Inject
protected RepositoryAssetService jcrRepositoryAssetService;

@Inject
@Preferred
private RulesRepository rulesRepository;

@Inject
protected GuidedRuleEditorService guidedRuleEditorService;

@Inject
protected MigrationPathManager migrationPathManager;

@Inject
@Named("ioStrategy")
private IOService ioService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@ public class GuidedScoreCardMigrater extends BaseAssetMigrater {

protected static final Logger logger = LoggerFactory.getLogger( GuidedScoreCardMigrater.class );

@Inject
protected RepositoryAssetService jcrRepositoryAssetService;

@Inject
protected GuidedRuleEditorService guidedRuleEditorService;

@Inject
protected MigrationPathManager migrationPathManager;

@Inject
@Named("ioStrategy")
private IOService ioService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ public class PlainTextAssetMigrater extends BaseAssetMigrater {

protected static final Logger logger = LoggerFactory.getLogger( PlainTextAssetMigrater.class );

@Inject
protected RepositoryAssetService jcrRepositoryAssetService;

@Inject
@Named("ioStrategy")
private IOService ioService;

@Inject
protected MigrationPathManager migrationPathManager;

public Path migrate( Module jcrModule,
AssetItem jcrAssetItem,
Path previousVersionPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ public class PlainTextAssetWithPackagePropertyMigrater extends BaseAssetMigrater

protected static final Logger logger = LoggerFactory.getLogger( PlainTextAssetWithPackagePropertyMigrater.class );

@Inject
protected RepositoryAssetService jcrRepositoryAssetService;

@Inject
@Named("ioStrategy")
private IOService ioService;

@Inject
protected MigrationPathManager migrationPathManager;

@Inject
DRLTextEditorService drlTextEditorServiceImpl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ public class TestScenarioMigrater extends BaseAssetMigrater {

protected static final Logger logger = LoggerFactory.getLogger( TestScenarioMigrater.class );

@Inject
protected RepositoryAssetService jcrRepositoryAssetService;

@Inject
protected MigrationPathManager migrationPathManager;

@Inject
@Named("ioStrategy")
private IOService ioService;
Expand Down

0 comments on commit 94ace31

Please sign in to comment.