Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bz-1000009: Jcr2vfs migration tool does not migrate 'globals'
- Loading branch information
Showing
4 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ation-core/src/main/java/org/drools/workbench/jcr2vfsmigration/migrater/GlobalParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.drools.workbench.jcr2vfsmigration.migrater; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
/** | ||
* Utility methods to parse a global Config | ||
*/ | ||
public final class GlobalParser { | ||
|
||
private static final String KEYWORD = "global "; | ||
|
||
private GlobalParser() { | ||
} | ||
|
||
public static List<String> parseGlobals( final String content ) { | ||
List<String> globals = new ArrayList<String>(); | ||
|
||
if ( content == null || content.trim().equals( "" ) ) { | ||
return globals; | ||
} else { | ||
final String[] lines = content.split( "\\n" ); | ||
|
||
for ( int i = 0; i < lines.length; i++ ) { | ||
String line = lines[ i ].trim(); | ||
if ( !( line.equals( "" ) || line.startsWith( "#" ) ) ) { | ||
if ( line.startsWith( KEYWORD ) ) { | ||
line = line.substring( KEYWORD.length() ).trim(); | ||
if ( line.endsWith( ";" ) ) { | ||
line = line.substring( 0, line.length() - 1 ); | ||
} | ||
globals.add( line ); | ||
} | ||
} | ||
} | ||
|
||
return globals; | ||
} | ||
|
||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
...re/src/main/java/org/drools/workbench/jcr2vfsmigration/migrater/asset/GlobalMigrater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.drools.workbench.jcr2vfsmigration.migrater.asset; | ||
|
||
import java.util.List; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
import org.drools.guvnor.client.common.AssetFormats; | ||
import org.drools.guvnor.client.rpc.Module; | ||
import org.drools.guvnor.server.RepositoryAssetService; | ||
import org.drools.repository.AssetItem; | ||
import org.drools.workbench.jcr2vfsmigration.migrater.GlobalParser; | ||
import org.drools.workbench.jcr2vfsmigration.migrater.PackageHeaderInfo; | ||
import org.drools.workbench.jcr2vfsmigration.migrater.PackageImportHelper; | ||
import org.drools.workbench.jcr2vfsmigration.migrater.util.DRLMigrationUtils; | ||
import org.drools.workbench.jcr2vfsmigration.migrater.util.MigrationPathManager; | ||
import org.uberfire.io.IOService; | ||
import org.uberfire.java.nio.base.options.CommentedOption; | ||
import org.uberfire.java.nio.file.Files; | ||
import org.uberfire.java.nio.file.StandardCopyOption; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.uberfire.backend.server.util.Paths; | ||
import org.uberfire.backend.vfs.Path; | ||
|
||
@ApplicationScoped | ||
public class GlobalMigrater extends BaseAssetMigrater { | ||
|
||
protected static final Logger logger = LoggerFactory.getLogger( GlobalMigrater.class ); | ||
|
||
@Inject | ||
protected RepositoryAssetService jcrRepositoryAssetService; | ||
|
||
@Inject | ||
private Paths paths; | ||
|
||
@Inject | ||
@Named("ioStrategy") | ||
private IOService ioService; | ||
|
||
@Inject | ||
protected MigrationPathManager migrationPathManager; | ||
|
||
@Inject | ||
private PackageHeaderInfo packageHeaderInfo; | ||
|
||
@Inject | ||
PackageImportHelper packageImportHelper; | ||
|
||
public Path migrate( Module jcrModule, | ||
List<String> globals) { | ||
if(globals.size() == 0) { | ||
return null; | ||
} | ||
|
||
Path path = migrationPathManager.generatePathForGlobal( jcrModule ); | ||
final org.uberfire.java.nio.file.Path nioPath = paths.convert( path ); | ||
|
||
if ( !Files.exists( nioPath ) ) { | ||
ioService.createFile( nioPath ); | ||
} | ||
|
||
StringBuffer content = new StringBuffer(); | ||
for(String global : globals) { | ||
content.append(global); | ||
content.append("\n"); | ||
} | ||
String contentWithPackage = packageImportHelper.assertPackageImportDRL(content.toString(), null); | ||
ioService.write( nioPath, | ||
contentWithPackage, | ||
new CommentedOption( jcrModule.getLastContributor(), | ||
null, | ||
jcrModule.getCheckinComment(), | ||
jcrModule.getLastModified() ) ); | ||
|
||
return path; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters