Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: shiv12095 <[email protected]>
  • Loading branch information
shiv12095 committed Apr 24, 2017
1 parent 82b3fe3 commit 4a1d9fc
Show file tree
Hide file tree
Showing 61 changed files with 1,827 additions and 1,357 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ bin/
.project
generated-sources
*.orig

devtool-project-repository/
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/
package org.eclipse.vorto.editor.datatype.web

import org.eclipse.vorto.editor.web.resource.HashMapResourceHandler
import org.eclipse.vorto.editor.web.resource.ContentTypeProvider
import org.eclipse.vorto.editor.web.resource.FileResourceHandler
import org.eclipse.vorto.editor.web.resource.WebEditorResourceSetProvider
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider
Expand All @@ -35,6 +36,10 @@ class DatatypeWebModule extends AbstractDatatypeWebModule {
}

def Class<? extends IServerResourceHandler> bindIServerResourceHandler() {
return HashMapResourceHandler;
return FileResourceHandler;
}

override bindIContentTypeProvider() {
return ContentTypeProvider
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/
package org.eclipse.vorto.editor.functionblock.web

import org.eclipse.vorto.editor.web.resource.HashMapResourceHandler
import org.eclipse.vorto.editor.web.resource.ContentTypeProvider
import org.eclipse.vorto.editor.web.resource.FileResourceHandler
import org.eclipse.vorto.editor.web.resource.WebEditorResourceSetProvider
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider
Expand All @@ -35,7 +36,10 @@ class FunctionblockWebModule extends AbstractFunctionblockWebModule {
}

def Class<? extends IServerResourceHandler> bindIServerResourceHandler() {
return HashMapResourceHandler;
return FileResourceHandler;
}

override bindIContentTypeProvider() {
return ContentTypeProvider
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/
package org.eclipse.vorto.editor.infomodel.web

import org.eclipse.vorto.editor.web.resource.ContentTypeProvider
import org.eclipse.vorto.editor.web.resource.FileResourceHandler
import org.eclipse.vorto.editor.web.resource.WebEditorResourceSetProvider
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider
import org.eclipse.xtext.web.server.persistence.IServerResourceHandler
import org.eclipse.vorto.editor.web.resource.HashMapResourceHandler

/**
* Use this class to register additional components to be used within the web application.
Expand All @@ -35,6 +36,10 @@ class InformationModelWebModule extends AbstractInformationModelWebModule {
}

def Class<? extends IServerResourceHandler> bindIServerResourceHandler() {
return HashMapResourceHandler;
return FileResourceHandler;
}

override bindIContentTypeProvider() {
return ContentTypeProvider
}
}
13 changes: 13 additions & 0 deletions framework/org.eclipse.vorto.editor.web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@
<artifactId>org.eclipse.xtend.lib</artifactId>
<version>${xtext.version}</version>
</dependency>

<!-- Project Repository Storage -->
<dependency>
<groupId>org.eclipse.vorto</groupId>
<artifactId>projectrepository-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.vorto</groupId>
<artifactId>projectrepository-file</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015-2016 Bosch Software Innovations GmbH and others.
* Copyright (c) 2017 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
Expand All @@ -12,19 +12,16 @@
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*/
package org.eclipse.vorto.server.devtool.models;
package org.eclipse.vorto.editor.web.resource

import java.util.ArrayList;
import org.eclipse.xtext.web.server.generator.DefaultContentTypeProvider
import org.eclipse.xtext.web.server.generator.GeneratorService

public class ProjectResourceListWrapper {
class ContentTypeProvider extends DefaultContentTypeProvider {

private ArrayList<ProjectResource> projectResourceList;

public ArrayList<ProjectResource> getProjectResourceList() {
return projectResourceList;
}

public void setProjectResourceList(ArrayList<ProjectResource> projectResourceList) {
this.projectResourceList = projectResourceList;
override getContentType(String fileName) {
if (fileName == GeneratorService.DEFAULT_ARTIFACT)
return 'text/html'
super.getContentType(fileName)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Copyright (c) 2017 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*/
package org.eclipse.vorto.editor.web.resource

import com.google.inject.Inject
import java.io.File
import java.io.IOException
import java.io.OutputStreamWriter
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.common.util.WrappedException
import org.eclipse.vorto.devtool.projectrepository.IProjectRepositoryService
import org.eclipse.vorto.devtool.projectrepository.file.ProjectRepositoryFileConstants
import org.eclipse.vorto.devtool.projectrepository.file.ProjectRepositoryServiceFS
import org.eclipse.xtext.parser.IEncodingProvider
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.web.server.IServiceContext
import org.eclipse.xtext.web.server.model.IWebDocumentProvider
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider
import org.eclipse.xtext.web.server.model.IXtextWebDocument
import org.eclipse.xtext.web.server.persistence.IServerResourceHandler

class FileResourceHandler implements IServerResourceHandler {

@Inject
private IWebResourceSetProvider resourceSetProvider

@Inject
private IWebDocumentProvider documentProvider

@Inject
private IEncodingProvider encodingProvider

private String projectRepositoryPath = "../devtool-project-repository";

private IProjectRepositoryService projectRepositoryService = new ProjectRepositoryServiceFS(projectRepositoryPath);

def getFileURI(String resourceId) {
val resource = projectRepositoryService.createQuery().property(ProjectRepositoryFileConstants.META_PROPERTY_RESOURCE_ID, resourceId).singleResult();
return URI.createFileURI(projectRepositoryPath + File.separator + resource.path);
}

override get(String resourceId, IServiceContext serviceContext) throws IOException {
try {
val uri = getFileURI(resourceId)
if (uri === null)
throw new IOException('The requested resource does not exist.')
val resourceSet = resourceSetProvider.get(resourceId, serviceContext)
val resource = resourceSet.getResource(uri, true) as XtextResource
println(resourceSet)
return documentProvider.get(resourceId, serviceContext) => [
setInput(resource)
]
} catch (WrappedException exception) {
throw exception.cause
}
}

override put(IXtextWebDocument document, IServiceContext serviceContext) throws IOException {
try {
val uri = getFileURI(document.resourceId)
val outputStream = document.resource.resourceSet.URIConverter.createOutputStream(uri)
val writer = new OutputStreamWriter(outputStream, encodingProvider.getEncoding(uri))
writer.write(document.text)
writer.close
} catch (WrappedException exception) {
throw exception.cause
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*******************************************************************************
* Copyright (c) 2016 Bosch Software Innovations GmbH and others.
/**
* Copyright (c) 2017 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
*
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*******************************************************************************/
*/
package org.eclipse.vorto.editor.web.resource

import com.google.inject.Inject
Expand All @@ -25,6 +25,7 @@ import org.eclipse.xtext.web.server.model.IXtextWebDocument
import org.eclipse.xtext.web.server.persistence.IServerResourceHandler
import org.eclipse.emf.common.util.WrappedException

@Deprecated
class HashMapResourceHandler implements IServerResourceHandler {

@Inject IWebResourceSetProvider resourceSetProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
/*******************************************************************************
* Copyright (c) 2016 Bosch Software Innovations GmbH and others.
/**
* Copyright (c) 2017 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
*
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*******************************************************************************/
*/
package org.eclipse.vorto.editor.web.resource

import com.google.inject.Inject
import java.util.HashSet
import java.util.Set
import javax.inject.Provider
import javax.inject.Singleton
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.xtext.web.server.IServiceContext
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider

@Singleton
class WebEditorResourceSetProvider implements IWebResourceSetProvider {

@Inject package Provider<ResourceSet> provider
Expand All @@ -36,31 +32,17 @@ class WebEditorResourceSetProvider implements IWebResourceSetProvider {
serviceContext.getSession().put("set", resourceSet)
}

def setSessionRefencedResourceSet(IServiceContext serviceContext, HashSet<String> referencedResourceSet) {
serviceContext.getSession().put("referenceSet", referencedResourceSet)
}

def ResourceSet getResourceSetFromSession(IServiceContext serviceContext) {
if (serviceContext.getSession().get("set") === null) {
var ResourceSet resourceSet = provider.get()
setSessionResourceSet(serviceContext, resourceSet);
return resourceSet
return getNewResourceSet(serviceContext);
} else {
return serviceContext.getSession().get("set")
}
}

def Set<String> getReferencedResourcesFromSession(IServiceContext serviceContext) {
if (serviceContext.getSession().get("referenceSet") === null) {
var HashSet<String> referencedResourceSet = new HashSet()
serviceContext.getSession().put("referenceSet", referencedResourceSet)
return referencedResourceSet
} else {
return serviceContext.getSession().get("referenceSet")
}
}

def ResourceSet getNewResourceSet() {
return provider.get();
def ResourceSet getNewResourceSet(IServiceContext serviceContext) {
var ResourceSet resourceSet = provider.get()
setSessionResourceSet(serviceContext, resourceSet);
return resourceSet
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,4 @@
</build>
</profile>
</profiles>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package org.eclipse.vorto.devtool.projectrepository.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.eclipse.vorto.devtool.projectrepository.file;

import org.eclipse.vorto.devtool.projectrepository.model.Resource;

public class ProjectRepositoryFileConstants {

public static final String META_PROPERTY_AUTHOR = Resource.META_PROPERTY_AUTHOR;

public static final String META_PROPERTY_RESOURCE_ID = "resourceId";

public static final String META_PROPERTY_NAME = "name";

public static final String META_PROPERTY_NAMESPACE = "namespace";

public static final String META_PROPERTY_VERSION = "version";

public static final String META_PROPERTY_MODEL_TYPE = "modelType";

public static final String META_PROPERTY_MODEL_SUB_TYPE = "modelSubType";

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public class ProjectRepositoryServiceFS implements IProjectRepositoryService {

protected String projectsDirectory = null;

public static final String META_PROPERTY_FILENAME = ".meta.props";
public static final String META_PROPERTY_CREATIONDATE = "meta.createdOn";
public static final String META_PROPERTY_FILENAME = ".meta.props";
public static final String META_PROPERTY_CREATIONDATE = "meta.createdOn";

private static final Logger log = LoggerFactory.getLogger(ProjectRepositoryServiceFS.class);

Expand Down Expand Up @@ -119,9 +119,13 @@ public void deleteResource(Resource resource) {
+ resource.getPath());
resource.setPath(projectsDirectory + File.separator
+ FilenameUtils.normalize(resource.getPath()));

File file = new File(resource.getPath());

String arr[] = resource.getPath().split(File.separator);
String folder = arr[arr.length-2];
File file = new File(resource.getPath());
File metaPropertyFile = new File(projectsDirectory + File.separator + FilenameUtils.normalize( folder + File.separator + "." + resource.getName() + META_PROPERTY_FILENAME));
FileUtils.deleteQuietly(file);
FileUtils.deleteQuietly(metaPropertyFile);
log.info("Resource deleted. (Name : " + resource.getName() + "; Path: "
+ resource.getPath() + ")");
}
Expand Down
Loading

0 comments on commit 4a1d9fc

Please sign in to comment.