diff options
author | Jihoon Song <jihoon80.song@samsung.com> | 2013-09-17 18:12:27 +0900 |
---|---|---|
committer | Jihoon Song <jihoon80.song@samsung.com> | 2013-09-25 13:28:18 +0900 |
commit | 9c404e0571be9293cca1d1bb6ceeeeee2de3c50b (patch) | |
tree | 1270c9d177249399926601b83636468721a0a6de /org.tizen.common.builder | |
parent | 805bfc9cab82e25ef25e68a8f2bf071eafbf0550 (diff) | |
download | common-eplugin-9c404e0571be9293cca1d1bb6ceeeeee2de3c50b.tar.gz common-eplugin-9c404e0571be9293cca1d1bb6ceeeeee2de3c50b.tar.bz2 common-eplugin-9c404e0571be9293cca1d1bb6ceeeeee2de3c50b.zip |
[Title] common-eplugin: added Dependency management using DB
[Desc.]
[Issue] #9960
Change-Id: I507b5fff2a33c5072fd5c16adc57b1fdeedee6f2
Diffstat (limited to 'org.tizen.common.builder')
11 files changed, 874 insertions, 70 deletions
diff --git a/org.tizen.common.builder/META-INF/MANIFEST.MF b/org.tizen.common.builder/META-INF/MANIFEST.MF index a1b4522fd..aed9e2df6 100644 --- a/org.tizen.common.builder/META-INF/MANIFEST.MF +++ b/org.tizen.common.builder/META-INF/MANIFEST.MF @@ -6,12 +6,14 @@ Bundle-Version: 2.0.0.qualifier Bundle-Vendor: %Bundle-Vendor Require-Bundle: org.eclipse.core.runtime, org.tizen.common, - org.eclipse.core.resources + org.eclipse.core.resources, + org.tizen.common.externals Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ClassPath: ., lib/jgrapht-jdk1.6.jar Export-Package: org.tizen.common.builder, org.tizen.common.builder.core, + org.tizen.common.builder.dependency, org.tizen.common.builder.exception Import-Package: org.tizen.common.verrari, org.tizen.common.verrari.engine, 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 7898ae52d..8349bc77a 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 @@ -30,19 +30,79 @@ package org.tizen.common.builder; import java.util.Set;
+
public interface BuildDependency
{
+
+ /**
+ * Adds the resource vertex
+ * @param resource {@link Resource}
+ */
void addVertex( Resource resource );
+
+ /**
+ * Returns whether contain the resource vertex or not
+ * @param resource {@link Resource}
+ */
boolean containsVertex( Resource resource );
+
+ /**
+ * Removes the resource vertex
+ * @param resource {@link Resource}
+ */
void removeVertex( Resource resource );
+ /**
+ * Adds a dependency edge with source and target resources
+ * @param in {@link Resource}
+ * @param out {@link Resource}
+ * @param dependency {@link Dependency}
+ */
void addEdge( Resource in, Resource out, Dependency dependency );
+
+ /**
+ * Removes a dependency edge
+ * @param dependency {@link Dependency}
+ */
void removeEdge( Dependency dependency );
+
+ /**
+ * Return dependency edges related with a resource
+ * @param resource {@link Resource}
+ * @return {@link Dependency} set
+ */
Set<Dependency> edgesOf( Resource resource );
+ /**
+ * Returns the source resource of dependency edge
+ * @param dependency {@link Dependency}
+ * @return {@link Resource}
+ */
Resource getEdgeSource( Dependency dependency );
+
+ /**
+ * Returns the target resource of dependency edge
+ * @param dependency {@link Dependency}
+ * @return {@link Resource}
+ */
Resource getEdgeTarget( Dependency dependency );
+ /**
+ * Initialize the dependency environment for build.<br>
+ * This method must be called before dependencies was manipulated.
+ *
+ * @param objs necessary information for initializing
+ */
+ 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 eff178cc5..d74ace440 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 @@ -34,7 +34,6 @@ import java.util.ArrayList; import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
@@ -43,6 +42,7 @@ import java.util.TreeSet; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tizen.common.builder.dependency.DependencyInMemory;
+import org.tizen.common.builder.dependency.JGraphDependency;
import org.tizen.common.builder.exception.BuildException;
import org.tizen.common.file.FileHandler;
import org.tizen.common.util.Assert;
@@ -55,33 +55,76 @@ public class BuildProcess protected final Logger logger = LoggerFactory.getLogger( getClass() );
- protected final HashMap<ResourceLayer, Builder> resources2builder = new HashMap<ResourceLayer, Builder>();
-
protected final List<Builder> builders = new ArrayList<Builder>();
+ protected final BuildDependency dependencies;
- protected final BuildDependency dependencies = new DependencyInMemory();
+ /**
+ * Default constructor using the memory dependencies ( {@link DependencyInMemory} )
+ */
+ public BuildProcess() {
+ this( new DependencyInMemory() );
+ }
- protected boolean bInitialize = false;
+ /**
+ * Constructor using another dependencies.<br>
+ * The client should override the {@code createDependency()} method for pair.
+ * @param dependencies {@link BuildDependency}
+ */
+ public BuildProcess(BuildDependency dependencies) {
+ Assert.notNull( dependencies );
+
+ this.dependencies = dependencies;
+ }
+
+ /**
+ * Returns the current dependencies.
+ * @return {@link BuildDependency}
+ */
+ public BuildDependency getDependencies() {
+ return this.dependencies;
+ }
+ /**
+ * Returns a new Dependency instance.
+ * @return {@link Dependency}
+ */
+ protected Dependency createDependency() {
+ return new JGraphDependency();
+ }
+ /**
+ * @param builder {@link Builder}
+ */
public
void
addBuilder(
final Builder builder
)
{
+ Assert.notNull( builder );
this.builders.add( builder );
}
+ /**
+ * @return {@link ResourceLayer} of last builder. If don't have a builder, return null.
+ */
public ResourceLayer getLastResourceLayer() {
Builder lastBuilder = getLastBuilder();
return (lastBuilder != null) ? lastBuilder.getResourceLayer() : null;
}
+ /**
+ * @return last {@link Builder}. If don't have a builder, return null.
+ */
public Builder getLastBuilder() {
return CollectionUtil.pickupLast( this.builders );
}
+ /**
+ * Find a builder by the ResourceLayer name.
+ * @param layerName for matching
+ * @return matched builder. If not found, return null;
+ */
public Builder getBuilder(String layerName) {
Assert.notNull( layerName );
@@ -100,6 +143,13 @@ public class BuildProcess return result;
}
+ /**
+ * Enable a builder with resources for rebuild.
+ * @param layerName for enabling
+ * @param resources for rebuild
+ * @throws IOException
+ * @throws BuildException
+ */
public void enableBuilder(String layerName, Resource ...resources) throws IOException, BuildException {
// get a builder
Builder builder = getBuilder( layerName );
@@ -128,6 +178,12 @@ public class BuildProcess this.removeResources( rebuildResource.toArray( new Resource[0] ) );
}
+ /**
+ * Disable a builder.
+ * @param layerName for disabling
+ * @throws BuildException
+ * @throws IOException
+ */
public void disableBuilder(String layerName) throws BuildException, IOException {
// get a builder
Builder builder = getBuilder( layerName );
@@ -163,6 +219,10 @@ public class BuildProcess this.removeResources( rebuildResource.toArray( new Resource[0] ) );
}
+ /**
+ * @param resources for sorting
+ * @return sorted resources
+ */
protected
Collection<Resource>
getSortedResource( Collection<Resource> resources )
@@ -194,6 +254,12 @@ public class BuildProcess }
+ /**
+ * Build resources incrementally using registered builders.<br>
+ * If middle resources are created while processing, reverse build automatically.
+ * @param resources exist in first resource layer
+ * @throws BuildException
+ */
public
void
build(
@@ -203,8 +269,10 @@ public class BuildProcess {
final Collection<Resource> sortedResources = getSortedResource( Arrays.asList( resources ) );
- try
- {
+ try {
+ // initialize dependencies with the last resource layer information.
+ this.dependencies.initialize( this.getLastResourceLayer() );
+
// Step#1 Remove dependency tree about resources what will be built
final Collection<Resource> projectedResources = new HashSet<Resource>();
for ( final Resource resource : sortedResources )
@@ -221,13 +289,15 @@ public class BuildProcess logger.debug( "{} th iteration :{}", i, iter );
iter = buildInternal( iter );
}
- } catch (IOException e)
- {
+ } catch (IOException e) {
throw new BuildException( e );
+ } finally {
+ // finalize dependencies like commit.
+ this.dependencies.close();
}
}
- public
+ protected
Collection<Resource>
buildInternal(
final Collection<Resource> resources
@@ -284,7 +354,7 @@ public class BuildProcess {
this.dependencies.addVertex( out );
}
- this.dependencies.addEdge( in, out, new Dependency() );
+ this.dependencies.addEdge( in, out, createDependency() );
next.add( out );
@@ -302,23 +372,38 @@ public class BuildProcess return next;
}
+ /**
+ * Remove resources with dependency and reverse build.
+ * @param resources for removing
+ * @throws BuildException
+ */
public void removeResources(Resource ... resources) throws BuildException {
final Collection<Resource> next = new LinkedHashSet<Resource>();
- // remove resources.
- for ( final Resource resource : resources )
- {
- try {
+ try {
+ this.dependencies.initialize( this.getLastResourceLayer() );
+
+ // remove resources.
+ for ( final Resource resource : resources )
+ {
next.addAll( removeResource( resource ) );
- } catch (IOException e) {
- throw new BuildException( e );
}
+
+ // reverse build
+ this.build( next.toArray( new Resource[0] ) );
+ } catch (IOException e) {
+ throw new BuildException( e );
+ } finally {
+ this.dependencies.close();
}
-
- // reverse build
- this.build( next.toArray( new Resource[0] ) );
}
+ /**
+ * Remove a resource.
+ * @param resource for removing
+ * @return resources for reverse build
+ * @throws IOException
+ */
protected
Collection<Resource>
removeResource(
@@ -379,6 +464,12 @@ public class BuildProcess return ret;
}
+ /**
+ * Find result resources at this time.
+ * @param resources for finding
+ * @return last built resources.
+ * @throws IOException
+ */
public Collection<Resource> getResult(Resource ... resources) throws IOException {
Collection<Resource> result = new HashSet<Resource>();
@@ -390,6 +481,11 @@ public class BuildProcess return result;
}
+ /**
+ * Check whether a filtering resource or not.
+ * @param resource for checking
+ * @return
+ */
protected boolean isValidResource(Resource resource) {
ResourceLayer iter = getLastBuilder().getResourceLayer();
@@ -404,6 +500,12 @@ public class BuildProcess return false;
}
+ /**
+ * Check whether built or not.
+ * @param currentLayer current {@link ResourceLayer}
+ * @param resource
+ * @return If already built in current layer, return true. Otherwise, return false.
+ */
protected boolean isBuiltResource(ResourceLayer currentLayer, Resource resource) {
logger.trace( "Resource :{}", resource );
diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/Dependency.java b/org.tizen.common.builder/src/org/tizen/common/builder/Dependency.java index dec0ec2c2..3a14a1062 100755 --- a/org.tizen.common.builder/src/org/tizen/common/builder/Dependency.java +++ b/org.tizen.common.builder/src/org/tizen/common/builder/Dependency.java @@ -28,44 +28,17 @@ */
package org.tizen.common.builder;
-import org.jgrapht.graph.DefaultEdge;
-
-public class Dependency
-extends DefaultEdge
-{
-
- private static final long serialVersionUID = -5661642289487372891L;
-
- protected Builder builder;
-
- public Dependency()
- {
- }
-
- public Dependency( final Builder builder )
- {
- this.builder = builder;
- }
-
- public Builder getBuilder()
- {
- return this.builder;
- }
-
- public void setBuilder( final Builder builder )
- {
- this.builder = builder;
- }
-
-
- public Resource getSource()
- {
- return (Resource) super.getSource();
- }
-
- public Resource getTarget()
- {
- return (Resource) super.getTarget();
- }
-
+public interface Dependency {
+
+ /**
+ * Returns the source resource of dependency edge
+ * @return {@link Resource}
+ */
+ public Resource getSource();
+
+ /**
+ * Returns the target resource of dependency edge
+ * @return {@link Resource}
+ */
+ public Resource getTarget();
}
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 new file mode 100644 index 000000000..93714c108 --- /dev/null +++ b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyConstant.java @@ -0,0 +1,52 @@ +/* + * Web IDE - Builder + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Kangho Kim <kh5325.kim@samsung.com> + * Hyeongseok Heo <hyeongseok.heo@samsung.com> + * Bonyong Lee <bonyong.lee@samsung.com> + * Jihoon Song <jihoon80.song@samsung.com> + * Taeyoung Son <taeyoung2.son@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package org.tizen.common.builder.dependency; + +public interface DependencyConstant { + + /** + * The Orient DataBase URL protocol using local storage. + */ + public static final String DB_PROTOCOL = "local:"; + + /** + * Resource path data key for storing vertex. + */ + public static final String RESOURCE_KEY_PATH = "path"; + + /** + * Resource layer data key for storing vertex. + */ + public static final String RESOURCE_KEY_LAYER = "layer"; + + /** + * Dependency data label for storing edge. + */ + public static final String EDGE_LABEL = "edge"; +} 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 new file mode 100644 index 000000000..f47700bc8 --- /dev/null +++ b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/DependencyInDB.java @@ -0,0 +1,277 @@ +/* + * Web IDE - Builder + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Kangho Kim <kh5325.kim@samsung.com> + * Hyeongseok Heo <hyeongseok.heo@samsung.com> + * Bonyong Lee <bonyong.lee@samsung.com> + * Jihoon Song <jihoon80.song@samsung.com> + * Taeyoung Son <taeyoung2.son@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package org.tizen.common.builder.dependency; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.builder.BuildDependency; +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 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.OrientVertex; + +public class DependencyInDB implements BuildDependency { + + protected final Logger logger = LoggerFactory.getLogger( getClass() ); + + public static final String DB_NAME = "Dependency"; + + protected OrientGraph graph; + protected ResourceLayer lastLayer; + protected String url; + + + /** + * Constructor + * @param dbAbsolutePath local database path + */ + public DependencyInDB(String dbAbsolutePath) { + setUrl( dbAbsolutePath ); + } + + /** + * Root URL setter for storing + * @param dbPath local database path. + */ + public void setUrl(String dbAbsolutePath) { + Assert.notNull( dbAbsolutePath ); + this.url = DependencyConstant.DB_PROTOCOL + dbAbsolutePath; // ex. "local:/home/dbstorage" + } + + /** + * ResourceLayer setter for matching resources. + * @param lastLayer last {@link ResourceLayer} of {@link BuildProcess} + */ + public void setLastResourceLayer(ResourceLayer lastLayer) { + Assert.notNull( lastLayer ); + this.lastLayer = lastLayer; + } + + /** + * 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. + */ + public void initialize(Object... objs) { + if ( objs != null ) { + for ( Object obj : objs ) { + if ( obj instanceof ResourceLayer ) { + setLastResourceLayer( (ResourceLayer) obj ); + } + } + } + + Assert.notNull( this.url ); + + if ( this.graph == null ) { + this.graph = new OrientGraph( this.url ); + this.graph.setUseLightweightEdges( false ); + + this.logger.trace( "Open OrientGraphDB : {}", this.url ); + } else { + this.logger.warn( "Failed to initialize because have already been initialized." ); + } + } + + /** + * Database will be closed. + */ + public void close() { + if ( this.graph != null ) { + this.graph.shutdown(); + this.graph = null; + + this.logger.trace( "Shutdown OrientGraphDB" ); + } else { + this.logger.warn( "Failed to shutdown because didn't be initialized." ); + } + } + + @Override + public boolean clear() { + this.initialize(); + + // remove database from local storage. + this.graph.drop(); + this.graph.shutdown(); + this.graph = null; + + this.logger.trace( "Remove OrientGraphDB storage" ); + return true; + } + + @Override + public void addVertex(Resource resource) { + Assert.notNull( resource ); + + OrientVertex vertex = this.graph.addVertex( null ); + vertex.setProperty( DependencyConstant.RESOURCE_KEY_PATH, resource.getPath() ); + vertex.setProperty( DependencyConstant.RESOURCE_KEY_LAYER, resource.getLayer().getName() ); + + this.graph.commit(); + this.logger.trace( "commit an added vertex : {}", resource ); + } + + protected Vertex getVertexFromDB(Resource resource) { + Assert.notNull( resource ); + + ResourceLayer layer = resource.getLayer(); + String layerName = layer.getName(); + Assert.notNull( layer ); + + Iterator<Vertex> iterator = this.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 ) ) { + return vertex; + } + } + } + + return null; + } + + @Override + public boolean containsVertex(Resource resource) { + return getVertexFromDB( resource ) != null; + } + + @Override + 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 ); + } + } + + @Override + public void addEdge(Resource in, Resource out, Dependency dependency) { + Vertex inVertex = getVertexFromDB( in ); + Vertex outVertex = getVertexFromDB( out ); + + 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 ); + } + + @Override + public void removeEdge(Dependency dependency) { + Assert.notNull( dependency ); + + OrientVertex inVertex = null; + OrientVertex outVertex = null; + + // get vertex values from dependency + if ( dependency instanceof OrientDBDependency ) { + OrientDBDependency depen = (OrientDBDependency) dependency; + inVertex = (OrientVertex) depen.getSourceVertex(); + outVertex = (OrientVertex) depen.getTargetVertex(); + } else { + // find a vertex from source resource + Vertex in = this.getVertexFromDB( dependency.getSource() ); + if ( in instanceof OrientVertex ) { + inVertex = (OrientVertex) in; + } + + // find a vertex from target resource + Vertex out = this.getVertexFromDB( dependency.getTarget() ); + if ( out instanceof OrientVertex ) { + outVertex = (OrientVertex) out; + } + } + + Assert.notNull( inVertex ); + Assert.notNull( outVertex ); + + // 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 ); + } + } + + @Override + public Set<Dependency> edgesOf(Resource resource) { + Assert.notNull( this.lastLayer ); + + Set<Dependency> result = new HashSet<Dependency>(); + + Vertex vertex = getVertexFromDB( resource ); + if ( vertex != null ) { + Iterator<Edge> iterator = vertex.getEdges( Direction.BOTH ).iterator(); + while( iterator.hasNext() ) { + Edge edge = iterator.next(); + + Vertex in = edge.getVertex( Direction.IN ); + Vertex out = edge.getVertex( Direction.OUT ); + result.add( new OrientDBDependency( in, out, this.lastLayer ) ); + } + } + + return result; + } + + @Override + public Resource getEdgeSource(Dependency dependency) { + return dependency.getSource(); + } + + @Override + public Resource getEdgeTarget(Dependency dependency) { + return dependency.getTarget(); + } +} 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 a97d3dfd2..d43cbfc60 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 @@ -95,4 +95,22 @@ implements BuildDependency return null;
}
+ @Override
+ public void initialize(Object... objs) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @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 13e4e31db..c61be7c26 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 @@ -74,7 +74,7 @@ implements BuildDependency * @param in
* @param out
* @param dependency
- * @see org.tizen.common.builder.BuildDependency#addEdge(org.tizen.common.builder.Resource, org.tizen.common.builder.Resource, org.tizen.common.builder.BuildProcess.Dependency)
+ * @see org.tizen.common.builder.BuildDependency#addEdge(org.tizen.common.builder.Resource, org.tizen.common.builder.Resource, org.tizen.common.builder.BuildProcess.JGraphDependency)
*/
public void addEdge(Resource in, Resource out, Dependency dependency)
{
@@ -83,7 +83,7 @@ implements BuildDependency /**
* @param dependency
- * @see org.tizen.common.builder.BuildDependency#removeEdge(org.tizen.common.builder.BuildProcess.Dependency)
+ * @see org.tizen.common.builder.BuildDependency#removeEdge(org.tizen.common.builder.BuildProcess.JGraphDependency)
*/
public void removeEdge(Dependency dependency)
{
@@ -103,7 +103,7 @@ implements BuildDependency /**
* @param dependency
* @return
- * @see org.tizen.common.builder.BuildDependency#getEdgeSource(org.tizen.common.builder.BuildProcess.Dependency)
+ * @see org.tizen.common.builder.BuildDependency#getEdgeSource(org.tizen.common.builder.BuildProcess.JGraphDependency)
*/
public Resource getEdgeSource(Dependency dependency)
{
@@ -113,15 +113,27 @@ implements BuildDependency /**
* @param dependency
* @return
- * @see org.tizen.common.builder.BuildDependency#getEdgeTarget(org.tizen.common.builder.BuildProcess.Dependency)
+ * @see org.tizen.common.builder.BuildDependency#getEdgeTarget(org.tizen.common.builder.BuildProcess.JGraphDependency)
*/
public Resource getEdgeTarget(Dependency dependency)
{
return dependencies.getEdgeTarget(dependency);
}
-
-
-
-
+ @Override
+ public void initialize(Object... objs) {
+ // do nothing
+ }
+
+ @Override
+ public void close() {
+ // do nothing
+ }
+
+ @Override
+ public boolean clear() {
+ // do nothing
+ return true;
+ }
+
}
diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/JGraphDependency.java b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/JGraphDependency.java new file mode 100755 index 000000000..148a030da --- /dev/null +++ b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/JGraphDependency.java @@ -0,0 +1,74 @@ +/*
+ * Web IDE - Builder
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Kangho Kim <kh5325.kim@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * Bonyong Lee <bonyong.lee@samsung.com>
+ * Jihoon Song <jihoon80.song@samsung.com>
+ * Taeyoung Son <taeyoung2.son@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+package org.tizen.common.builder.dependency;
+
+import org.jgrapht.graph.DefaultEdge;
+import org.tizen.common.builder.Builder;
+import org.tizen.common.builder.Dependency;
+import org.tizen.common.builder.Resource;
+
+public class JGraphDependency
+extends DefaultEdge implements Dependency
+{
+
+ private static final long serialVersionUID = -5661642289487372891L;
+
+ protected Builder builder;
+
+ public JGraphDependency()
+ {
+ }
+
+ public JGraphDependency( final Builder builder )
+ {
+ this.builder = builder;
+ }
+
+ public Builder getBuilder()
+ {
+ return this.builder;
+ }
+
+ public void setBuilder( final Builder builder )
+ {
+ this.builder = builder;
+ }
+
+
+ public Resource getSource()
+ {
+ return (Resource) super.getSource();
+ }
+
+ public Resource getTarget()
+ {
+ return (Resource) super.getTarget();
+ }
+
+}
diff --git a/org.tizen.common.builder/src/org/tizen/common/builder/dependency/OrientDBDependency.java b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/OrientDBDependency.java new file mode 100644 index 000000000..3fdb3b782 --- /dev/null +++ b/org.tizen.common.builder/src/org/tizen/common/builder/dependency/OrientDBDependency.java @@ -0,0 +1,91 @@ +/* + * Web IDE - Builder + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Kangho Kim <kh5325.kim@samsung.com> + * Hyeongseok Heo <hyeongseok.heo@samsung.com> + * Bonyong Lee <bonyong.lee@samsung.com> + * Jihoon Song <jihoon80.song@samsung.com> + * Taeyoung Son <taeyoung2.son@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package org.tizen.common.builder.dependency; + +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 com.tinkerpop.blueprints.Vertex; + +public class OrientDBDependency implements Dependency { + + protected Vertex source; + protected Vertex target; + + protected ResourceLayer resourceLayer; + + + protected OrientDBDependency(Vertex source, Vertex target, ResourceLayer resourceLayer) { + Assert.notNull( source ); + Assert.notNull( target ); + Assert.notNull( resourceLayer ); + + this.source = source; + this.target = target; + + this.resourceLayer = resourceLayer; + } + + protected Resource convertVertexToResource(Vertex vertex, ResourceLayer lastLayer) { + String path = vertex.getProperty( DependencyConstant.RESOURCE_KEY_PATH ); + String layer = vertex.getProperty( DependencyConstant.RESOURCE_KEY_LAYER ); + + ResourceLayer resourceLayer = lastLayer; + while ( resourceLayer != null ) { + if ( resourceLayer.getName().equals( layer ) ) { + return new Resource( resourceLayer, path ); + } + + resourceLayer = resourceLayer.getParent(); + } + + return null; + } + + public Vertex getSourceVertex() { + return this.source; + } + + public Vertex getTargetVertex() { + return this.target; + } + + @Override + public Resource getSource() { + return convertVertexToResource( this.source, this.resourceLayer ); + } + + @Override + public Resource getTarget() { + return convertVertexToResource( this.target, this.resourceLayer ); + } + +} 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 new file mode 100644 index 000000000..e4a907e4d --- /dev/null +++ b/org.tizen.common.builder/test/src/org/tizen/common/builder/DependencyInDBTest.java @@ -0,0 +1,143 @@ +package org.tizen.common.builder; + +import static org.junit.Assert.*; +import static org.tizen.common.util.IOUtil.tryClose; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.runtime.Path; +import org.junit.Test; +import org.tizen.common.builder.BuildProcess; +import org.tizen.common.builder.Builder; +import org.tizen.common.builder.Resource; +import org.tizen.common.builder.ResourceLayer; +import org.tizen.common.builder.dependency.DependencyInDB; +import org.tizen.common.file.FileHandler; +import org.tizen.common.file.VirtualFileHandler; +import org.tizen.common.util.Assert; + + +public class DependencyInDBTest extends AbstractTestCase { + + protected class ExtensionFilterMockBuilder extends MockBuilder { + + protected String extension = ""; + + public ExtensionFilterMockBuilder(ResourceLayer layer, String extension) { + super(layer); + + Assert.notNull( extension ); + this.extension = extension; + } + + @Override + public boolean canBuild(Resource resource) { + try { + return resource != null && resource.getName().endsWith( this.extension ); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + } + + protected final String[] resourcePaths = { + "/a.js", "/b.js", "/c.js", "/a.css", "/b.css", "/a.html", "/b.html" + }; + protected final String testStorageName = "testDB"; + + + protected void load( FileHandler fileHandler, String path ) throws IOException { + final URL u = new URL( "cp://" + path ); + final InputStream in = u.openStream(); + try { + fileHandler.write( path, in ); + } finally { + tryClose( in ); + } + } + + protected void loadResources(FileHandler fileHandler) throws IOException { + for ( String path : this.resourcePaths ) { + load( fileHandler, path ); + } + } + + protected Resource[] createResources(ResourceLayer layer) { + List<Resource> resources = new ArrayList<Resource>(); + for ( String path : this.resourcePaths ) { + resources.add( new Resource( layer, path ) ); + } + + return resources.toArray( new Resource[0] ); + } + + @Test + public void test_build() throws Exception { + + // create resource layers + final ResourceLayer fileLayer = new ResourceLayer( "local", new VirtualFileHandler() ); + final ResourceLayer firstLayer = new ResourceLayer( "first", fileLayer, new VirtualFileHandler() ); + final ResourceLayer secondLayer = new ResourceLayer( "second", firstLayer, new VirtualFileHandler() ); + + // load contents + loadResources( fileLayer.getFileHandler() ); + + // create builders + Builder firstMockBuilder = new ExtensionFilterMockBuilder( firstLayer, "js" ); + 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() ); + + // 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(); + + Object[][] TEST_CASES = { + { new Resource( fileLayer, "/a.js" ), new Resource( firstLayer, "/a.js" ) }, + { new Resource( fileLayer, "/b.js" ), new Resource( firstLayer, "/b.js" ) }, + { new Resource( fileLayer, "/c.js" ), new Resource( firstLayer, "/c.js" ) }, + { new Resource( fileLayer, "/a.css" ), null }, + { new Resource( fileLayer, "/b.css" ), null }, + { new Resource( fileLayer, "/a.html" ), new Resource( secondLayer, "/a.html" ) }, + { new Resource( fileLayer, "/b.html" ), new Resource( secondLayer, "/b.html" ) }, + }; + + for ( Object[] TEST_CASE : TEST_CASES ) { + Resource source = (Resource) TEST_CASE[0]; + Resource target = (Resource) TEST_CASE[1]; + + Iterator<Dependency> iterator = didb.edgesOf( source ).iterator(); + if ( target == null ) { + assertFalse( iterator.hasNext() ); + assertFalse( didb.containsVertex( source ) ); + } else { + assertTrue( iterator.hasNext() ); + + Dependency next = iterator.next(); + assertEquals( source, next.getSource() ); + assertEquals( target, next.getTarget() ); + } + } + } finally { + didb.close(); + } + } +} |