Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
BV-1063436 and BZ-1045117: new project creates just one commit + fixi…
Browse files Browse the repository at this point in the history
…ng double commits on file creation.
  • Loading branch information
porcelli committed Feb 10, 2014
1 parent 5916927 commit a8ba1bb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Expand Up @@ -31,6 +31,7 @@
import org.uberfire.java.nio.base.options.CommentedOption;
import org.uberfire.backend.server.util.Paths;
import org.uberfire.backend.vfs.Path;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.security.Identity;

Expand Down Expand Up @@ -74,7 +75,10 @@ public Path setUpKModuleStructure( final Path projectRoot ) {
ioService.createDirectory( nioRoot.resolve( "src/test/resources" ) );

final org.uberfire.java.nio.file.Path pathToKModuleXML = nioRoot.resolve( "src/main/resources/META-INF/kmodule.xml" );
ioService.createFile( pathToKModuleXML );
if ( ioService.exists( pathToKModuleXML ) ) {
throw new FileAlreadyExistsException( pathToKModuleXML.toString() );
}

ioService.write( pathToKModuleXML,
moduleContentHandler.toString( new KModuleModel() ) );

Expand Down
Expand Up @@ -12,6 +12,7 @@
import org.uberfire.java.nio.base.options.CommentedOption;
import org.uberfire.backend.server.util.Paths;
import org.uberfire.backend.vfs.Path;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.rpc.SessionInfo;
import org.uberfire.security.Identity;

Expand Down Expand Up @@ -68,7 +69,9 @@ public Path create( final Path projectRoot,
final org.uberfire.java.nio.file.Path nioRoot = Paths.convert( projectRoot );
pathToPOMXML = nioRoot.resolve( "pom.xml" );

ioService.createFile( pathToPOMXML );
if ( ioService.exists( pathToPOMXML ) ) {
throw new FileAlreadyExistsException( pathToPOMXML.toString() );
}
ioService.write( pathToPOMXML,
pomContentHandler.toString( pomModel ) );

Expand Down
Expand Up @@ -575,6 +575,8 @@ public Project newProject( final Repository repository,
final Path fsRoot = repository.getRoot();
final Path projectRootPath = Paths.convert( Paths.convert( fsRoot ).resolve( projectName ) );

ioService.startBatch( makeCommentedOption( "New project [" + projectName + "]" ) );

//Set-up project structure and KModule.xml
kModuleService.setUpKModuleStructure( projectRootPath );

Expand All @@ -585,7 +587,10 @@ public Project newProject( final Repository repository,

//Create Project configuration
final Path projectConfigPath = Paths.convert( Paths.convert( projectRootPath ).resolve( PROJECT_IMPORTS_PATH ) );
ioService.createFile( Paths.convert( projectConfigPath ) );

if ( ioService.exists( Paths.convert( projectConfigPath ) ) ) {
throw new FileAlreadyExistsException( projectConfigPath.toString() );
}
ioService.write( Paths.convert( projectConfigPath ),
projectConfigurationContentHandler.toString( createProjectImports() ) );

Expand All @@ -606,6 +611,8 @@ public Project newProject( final Repository repository,
final Package defaultWorkspacePackage = doNewPackage( defaultPackage,
defaultWorkspacePath );

ioService.endBatch();

//Raise an event for the new project's default workspace
newPackageEvent.fire( new NewPackageEvent( defaultWorkspacePackage ) );

Expand Down
Expand Up @@ -363,8 +363,8 @@ public Map<String, Object> setUpAttributes( final Path path,
if ( metadata != null ) {
attributes = configAttrs( attributes, metadata );
}
return attributes;

return BasicFileAttributesUtil.cleanup( attributes );
} catch ( Exception e ) {
throw ExceptionUtilities.handleException( e );
}
Expand Down

2 comments on commit a8ba1bb

@psiroky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,
shouldn't be the code between ioService.startBatch() and ioService.endBatch() in try-catch block? It seems that if an exception is thrown after the startBatch() and before endBatch(), the ioService will stay blocked forever and thus it won't be possible to create new commits. The finally block should then call endBatch() or in case of error just unlock the ioService.

Note: I haven't studied in deep the implementation of ioService.startBatch(), so I might be missing something.

@porcelli
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psiroky yes, you're completely right! i did this quickly to test, faced a different issue, and never return to fix original quick and dirty. thx!

Please sign in to comment.