diff options
Diffstat (limited to 'org.tizen.common.builder')
7 files changed, 140 insertions, 99 deletions
diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/BuildDependency.java b/org.tizen.common.builder/src/org/tizen/common/builder/BuildDependency.java index 8349bc77a..a3e01a032 100755 --- a/org.tizen.common.builder/src/org/tizen/common/builder/BuildDependency.java +++ b/org.tizen.common.builder/src/org/tizen/common/builder/BuildDependency.java @@ -96,12 +96,6 @@ public interface BuildDependency void initialize(Object... objs);
/**
- * Close the dependency environment for build.<br>
- * This method must be called after dependencies was manipulated.
- */
- void close();
-
- /**
* Clear the all dependencies and vertexes.
*/
boolean clear();
diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java b/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java index d74ace440..6e079fc4b 100755 --- a/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java +++ b/org.tizen.common.builder/src/org/tizen/common/builder/BuildProcess.java @@ -291,9 +291,6 @@ public class BuildProcess }
} catch (IOException e) {
throw new BuildException( e );
- } finally {
- // finalize dependencies like commit.
- this.dependencies.close();
}
}
@@ -393,8 +390,6 @@ public class BuildProcess this.build( next.toArray( new Resource[0] ) );
} catch (IOException e) {
throw new BuildException( e );
- } finally {
- this.dependencies.close();
}
}
diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyConstant.java b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyConstant.java index 93714c108..03af4b833 100644 --- a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyConstant.java +++ b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyConstant.java @@ -45,8 +45,10 @@ public interface DependencyConstant { */ public static final String RESOURCE_KEY_LAYER = "layer"; + public static final String RESOURCE_KEY_PROJECT = "project"; + /** * Dependency data label for storing edge. */ public static final String EDGE_LABEL = "edge"; -} +}
\ No newline at end of file diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInDB.java b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInDB.java index f47700bc8..501877efd 100644 --- a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInDB.java +++ b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInDB.java @@ -28,6 +28,7 @@ */ package org.tizen.common.builder.dependency; +import java.io.File; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -39,40 +40,60 @@ import org.tizen.common.builder.Dependency; import org.tizen.common.builder.Resource; import org.tizen.common.builder.ResourceLayer; import org.tizen.common.util.Assert; +import org.tizen.common.util.StringUtil; import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.orient.OrientEdge; -import com.tinkerpop.blueprints.impls.orient.OrientGraph; +import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; import com.tinkerpop.blueprints.impls.orient.OrientVertex; public class DependencyInDB implements BuildDependency { - protected final Logger logger = LoggerFactory.getLogger( getClass() ); + protected static final Logger logger = LoggerFactory.getLogger( DependencyInDB.class ); public static final String DB_NAME = "Dependency"; - protected OrientGraph graph; - protected ResourceLayer lastLayer; - protected String url; + protected static OrientGraphNoTx graph; // db instance + protected static String path; // absolute path for database storing + protected static String url; // be made from the path + + protected String projectName; // project of resource + protected ResourceLayer lastLayer; // last resource layer for data sync /** - * Constructor - * @param dbAbsolutePath local database path + * Root URL setter for storing. If dbAbsoultePath is an empty, use the previous path. + * @param dbPath local database path. */ - public DependencyInDB(String dbAbsolutePath) { - setUrl( dbAbsolutePath ); + public static synchronized void setUrl(String dbAbsolutePath) { + Assert.isNull( graph ); + + // ( previous path : null, argument : null ) = Assertion + // ( previous path : not null, argument : null ) = use previous path + // ( previous path : null, argument : not null ) = use argument + // ( previous path : not null, argument : not null ) = use argument + + if ( StringUtil.isEmpty( path ) ) { + Assert.notNull( dbAbsolutePath ); + } + + if ( ! StringUtil.isEmpty( dbAbsolutePath ) ) { + path = dbAbsolutePath; + } + + url = DependencyConstant.DB_PROTOCOL + path; // ex. "local:/home/dbstorage" } /** - * Root URL setter for storing - * @param dbPath local database path. + * Information setter for resource separation. + * This method must be called more than once before access methods be used. + * @param projectName for resource separation. */ - public void setUrl(String dbAbsolutePath) { - Assert.notNull( dbAbsolutePath ); - this.url = DependencyConstant.DB_PROTOCOL + dbAbsolutePath; // ex. "local:/home/dbstorage" + public void setProjectName(String projectName) { + Assert.notNull( projectName ); + this.projectName = projectName; } /** @@ -85,86 +106,132 @@ public class DependencyInDB implements BuildDependency { } /** - * Database will be opened.<br> - * Can be set the last resource layer by arguments<br> - * <b>Important : </b>The client is responsible for calling the close method when finished. + * Database will be opened. If doesn't exist, create both a storage and an index. + * This method must be called when this class have the url information. */ - public void initialize(Object... objs) { - if ( objs != null ) { - for ( Object obj : objs ) { - if ( obj instanceof ResourceLayer ) { - setLastResourceLayer( (ResourceLayer) obj ); - } - } - } + public static synchronized void open(String dbAbsolutePath) { + setUrl( dbAbsolutePath ); - Assert.notNull( this.url ); + Assert.notNull( url ); - if ( this.graph == null ) { - this.graph = new OrientGraph( this.url ); - this.graph.setUseLightweightEdges( false ); + if ( graph == null ) { + // check for creating first + boolean bCreateIndex = false; + if ( ! new File( path ).exists() ) { + bCreateIndex = true; + } - this.logger.trace( "Open OrientGraphDB : {}", this.url ); + // create or open DB + graph = new OrientGraphNoTx( url ); + graph.setUseLightweightEdges( false ); + + // create indexes + if ( bCreateIndex ) { + graph.createKeyIndex( DependencyConstant.RESOURCE_KEY_PATH, Vertex.class ); + } + + logger.info( "Open OrientGraphDB : {}", url ); } else { - this.logger.warn( "Failed to initialize because have already been initialized." ); + logger.info( "Failed to open because have already been opened." ); } } /** * Database will be closed. */ - public void close() { - if ( this.graph != null ) { - this.graph.shutdown(); - this.graph = null; + public static synchronized void close() { + if ( graph != null ) { + graph.commit(); + graph.shutdown(); + graph = null; - this.logger.trace( "Shutdown OrientGraphDB" ); + logger.info( "Shutdown OrientGraphDB" ); } else { - this.logger.warn( "Failed to shutdown because didn't be initialized." ); + logger.info( "Failed to shutdown because didn't be initialized." ); + } + } + + /** + * Can be set the last resource layer by arguments + */ + @Override + public void initialize(Object... objs) { + if ( objs != null ) { + for ( Object obj : objs ) { + if ( obj instanceof ResourceLayer ) { + setLastResourceLayer( (ResourceLayer) obj ); + } + } } } @Override public boolean clear() { - this.initialize(); + Assert.notNull( this.projectName ); // remove database from local storage. - this.graph.drop(); - this.graph.shutdown(); - this.graph = null; + Iterator<Edge> eIter = graph.getEdges( DependencyConstant.RESOURCE_KEY_PROJECT, this.projectName ).iterator(); + while ( eIter.hasNext() ) { + Edge next = eIter.next(); + graph.removeEdge( next ); + } + Iterator<Vertex> vIter = graph.getVertices( DependencyConstant.RESOURCE_KEY_PROJECT, this.projectName ).iterator(); + while ( vIter.hasNext() ) { + Vertex next = vIter.next(); + graph.removeVertex( next ); + } + + logger.trace( "Remove all resources" ); - this.logger.trace( "Remove OrientGraphDB storage" ); return true; } + public void clearAll() { + Assert.notNull( graph ); + + graph.drop(); + } + @Override public void addVertex(Resource resource) { + Assert.notNull( this.projectName ); Assert.notNull( resource ); - OrientVertex vertex = this.graph.addVertex( null ); + OrientVertex vertex = graph.addVertex( null ); vertex.setProperty( DependencyConstant.RESOURCE_KEY_PATH, resource.getPath() ); vertex.setProperty( DependencyConstant.RESOURCE_KEY_LAYER, resource.getLayer().getName() ); + vertex.setProperty( DependencyConstant.RESOURCE_KEY_PROJECT, this.projectName ); - this.graph.commit(); - this.logger.trace( "commit an added vertex : {}", resource ); + logger.trace( "an added vertex : {}", resource ); } + /** + * Returns a vertex from Database using resource information. + * @param resource information for searching + * @return If not found, return null. Otherwise return a vertex + */ protected Vertex getVertexFromDB(Resource resource) { + Assert.notNull( this.projectName ); Assert.notNull( resource ); ResourceLayer layer = resource.getLayer(); - String layerName = layer.getName(); Assert.notNull( layer ); - Iterator<Vertex> iterator = this.graph.getVertices( + String layerName = layer.getName(); + + Iterator<Vertex> iterator = graph.getVertices( DependencyConstant.RESOURCE_KEY_PATH, resource.getPath() ).iterator(); while( iterator.hasNext() ) { Vertex vertex = iterator.next(); + Object value = vertex.getProperty( DependencyConstant.RESOURCE_KEY_LAYER ); - if ( value instanceof String ) { - if ( ( (String) value ) .equals( layerName ) ) { + Object project = vertex.getProperty( DependencyConstant.RESOURCE_KEY_PROJECT ); + + if ( ( value instanceof String ) && ( project instanceof String ) ) { + if ( ((String) value).equals( layerName ) && + ((String) project).equals( this.projectName ) ) { return vertex; } } @@ -182,9 +249,8 @@ public class DependencyInDB implements BuildDependency { public void removeVertex(Resource resource) { Vertex vertex = getVertexFromDB( resource ); if ( vertex != null ) { - this.graph.removeVertex( vertex ); - this.graph.commit(); - this.logger.trace( "commit a removed vertex : {}", resource ); + graph.removeVertex( vertex ); + logger.trace( "a removed vertex : {}", resource ); } } @@ -196,9 +262,8 @@ public class DependencyInDB implements BuildDependency { Assert.notNull( inVertex ); Assert.notNull( outVertex ); - OrientEdge edge = this.graph.addEdge( null, outVertex, inVertex, DependencyConstant.EDGE_LABEL ); - this.graph.commit(); - this.logger.trace( "commit an added edge : {}", edge ); + OrientEdge edge = graph.addEdge( null, outVertex, inVertex, DependencyConstant.EDGE_LABEL ); + logger.trace( "an added edge : {}", edge ); } @Override @@ -232,15 +297,10 @@ public class DependencyInDB implements BuildDependency { // remove edges Iterator<Edge> iterator = inVertex.getEdges( outVertex, Direction.IN ).iterator(); - int cnt = 0; // removed count while( iterator.hasNext() ) { - this.graph.removeEdge( iterator.next() ); - cnt++; - } - - if ( cnt > 0 ) { - this.graph.commit(); - this.logger.trace( "commit removed edges ( {} )", cnt ); + Edge edge = iterator.next(); + graph.removeEdge( edge ); + logger.trace( "an removed edge : {}", edge ); } } diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInFile.java b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInFile.java index d43cbfc60..fdb836b80 100755 --- a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInFile.java +++ b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInFile.java @@ -102,12 +102,6 @@ implements BuildDependency }
@Override
- public void close() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
public boolean clear() {
// TODO Auto-generated method stub
return false;
diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInMemory.java b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInMemory.java index c61be7c26..9a550aeec 100755 --- a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInMemory.java +++ b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInMemory.java @@ -126,11 +126,6 @@ implements BuildDependency }
@Override
- public void close() {
- // do nothing
- }
-
- @Override
public boolean clear() {
// do nothing
return true;
diff --git a/org.tizen.common.builder/test/src/org/tizen/common/builder/DependencyInDBTest.java b/org.tizen.common.builder/test/src/org/tizen/common/builder/DependencyInDBTest.java index e4a907e4d..5dac5ebfc 100644 --- a/org.tizen.common.builder/test/src/org/tizen/common/builder/DependencyInDBTest.java +++ b/org.tizen.common.builder/test/src/org/tizen/common/builder/DependencyInDBTest.java @@ -94,22 +94,22 @@ public class DependencyInDBTest extends AbstractTestCase { Builder secondMockBuilder = new ExtensionFilterMockBuilder( secondLayer, "html" ); // create DependencyInDB for main test - // TODO: where do you make a temporary database storage for test? - String storagepath = new File( testStorageName ).getAbsolutePath(); - DependencyInDB didb = new DependencyInDB( new Path( storagepath ).toString() ); + String storageAbsPath = new File( testStorageName ).getAbsolutePath(); + DependencyInDB.open( new Path( storageAbsPath ).toString() ); + DependencyInDB didb = new DependencyInDB(); + didb.setProjectName( "local" ); - // create BuildProcess and add builders - BuildProcess buildProcess = new BuildProcess( didb ); - buildProcess.addBuilder( firstMockBuilder ); - buildProcess.addBuilder( secondMockBuilder ); - // build - buildProcess.build( createResources( fileLayer ) ); - - // check database try { - didb.initialize(); + // create BuildProcess and add builders + BuildProcess buildProcess = new BuildProcess( didb ); + buildProcess.addBuilder( firstMockBuilder ); + buildProcess.addBuilder( secondMockBuilder ); + + // build + buildProcess.build( createResources( fileLayer ) ); + // check database Object[][] TEST_CASES = { { new Resource( fileLayer, "/a.js" ), new Resource( firstLayer, "/a.js" ) }, { new Resource( fileLayer, "/b.js" ), new Resource( firstLayer, "/b.js" ) }, @@ -137,7 +137,8 @@ public class DependencyInDBTest extends AbstractTestCase { } } } finally { - didb.close(); + didb.clearAll(); + DependencyInDB.close(); } } } |