use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method initProxyRepository.
/**
* DOC talend Comment method "initProxyRepository".
*/
public static void initProxyRepository(IProject rootProject) {
Project project = null;
ProxyRepositoryFactory proxyRepository = ProxyRepositoryFactory.getInstance();
IRepositoryFactory repository = RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_LOCAL_ID);
if (repository == null) {
log.fatal(DefaultMessagesImpl.getString(// $NON-NLS-1$
"No local Repository found! Probably due to a missing plugin in the product."));
}
proxyRepository.setRepositoryFactoryFromProvider(repository);
try {
proxyRepository.checkAvailability();
proxyRepository.initialize();
XmiResourceManager xmiResourceManager = new XmiResourceManager();
if (rootProject.getFile(FileConstants.LOCAL_PROJECT_FILENAME).exists()) {
// Initialize TDQ EMF model packages.
new EMFUtil();
project = new Project(xmiResourceManager.loadProject(rootProject));
} else {
User user = org.talend.core.model.properties.impl.PropertiesFactoryImpl.eINSTANCE.createUser();
// $NON-NLS-1$
user.setLogin("talend@talend.com");
// $NON-NLS-1$
user.setPassword("talend@talend.com".getBytes());
String projectName = rootProject.getName();
String projectDesc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName).getComment();
Project projectInfor = ProjectHelper.createProject(projectName, projectDesc, ECodeLanguage.JAVA.getName(), user);
// MOD zshen create project by proxyRepository
checkFileName(projectInfor.getLabel(), RepositoryConstants.PROJECT_PATTERN);
project = proxyRepository.getRepositoryFactoryFromProvider().createProject(projectInfor);
}
if (project != null) {
initRepositoryContext(project);
// add status
// $NON-NLS-1$
String defaultTechnicalStatusList = "DEV development;TEST testing;PROD production";
List<Status> statusList = StatusHelper.parse(defaultTechnicalStatusList);
proxyRepository.setTechnicalStatus(statusList);
}
} catch (PersistenceException e) {
Assert.fail(e.getMessage());
}
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class ItemRecordTest method initProxyRepository.
/**
* DOC talend Comment method "initProxyRepository".
*/
private void initProxyRepository(IProject rootProject) {
Project project = null;
// $NON-NLS-1$
log.debug("##############ProxyRepositoryFactory.getInstance()");
ProxyRepositoryFactory proxyRepository = ProxyRepositoryFactory.getInstance();
// $NON-NLS-1$
log.debug("##############RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_LOCAL_ID)");
IRepositoryFactory repository = RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_LOCAL_ID);
proxyRepository.setRepositoryFactoryFromProvider(repository);
try {
// $NON-NLS-1$
log.debug("##############proxyRepository.checkAvailability()");
proxyRepository.checkAvailability();
// $NON-NLS-1$
log.debug("##############proxyRepository.initialize()");
try {
proxyRepository.initialize();
} catch (Exception e) {
log.error(e, e);
}
proxyRepository.logOffProject();
XmiResourceManager xmiResourceManager = new XmiResourceManager();
// $NON-NLS-1$
log.debug("##############rootProject.getFile(FileConstants.LOCAL_PROJECT_FILENAME).exists()");
if (rootProject.getFile(FileConstants.LOCAL_PROJECT_FILENAME).exists()) {
// Initialize TDQ EMF model packages.
// $NON-NLS-1$
log.debug("##############Project name is " + rootProject.getName());
new EMFUtil();
project = new Project(xmiResourceManager.loadProject(rootProject));
// $NON-NLS-1$
log.debug("############## after loadProject Project name is " + project.getTechnicalLabel());
} else {
User user = org.talend.core.model.properties.impl.PropertiesFactoryImpl.eINSTANCE.createUser();
// $NON-NLS-1$
user.setLogin("talend@talend.com");
// $NON-NLS-1$
user.setPassword("talend@talend.com".getBytes());
String projectName = rootProject.getName();
// $NON-NLS-1$
log.debug("##############default project is not exist then create new project which is " + projectName);
String projectDesc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName).getComment();
Project projectInfor = ProjectHelper.createProject(projectName, projectDesc, ECodeLanguage.JAVA.getName(), user);
// MOD zshen create project by proxyRepository
checkFileName(projectInfor.getLabel(), RepositoryConstants.PROJECT_PATTERN);
project = proxyRepository.getRepositoryFactoryFromProvider().createProject(projectInfor);
}
if (project != null) {
initRepositoryContext(project);
// add status
// $NON-NLS-1$
String defaultTechnicalStatusList = "DEV development;TEST testing;PROD production";
List<Status> statusList = StatusHelper.parse(defaultTechnicalStatusList);
proxyRepository.setTechnicalStatus(statusList);
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
Assert.fail(e.getMessage());
} catch (Exception e) {
log.error(e, e);
// $NON-NLS-1$
log.debug("##############exception message is " + e.getMessage());
}
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class UpdatePathProperty method doExecute.
/*
* (non-Jsdoc)
*
* @see org.talend.dataprofiler.core.migration.AMigrationTask#doExecute()
*/
@Override
protected boolean doExecute() throws Exception {
boolean ok = true;
EMFUtil emfUtil = new EMFUtil();
for (File file : fileList) {
if (file.isFile()) {
URI uri = URI.createFileURI(file.getAbsolutePath());
if (log.isDebugEnabled()) {
// $NON-NLS-1$
log.debug("---------Translate " + uri.toString());
}
Property property = null;
try {
Resource resource = emfUtil.getResourceSet().getResource(uri, true);
for (EObject object : resource.getContents()) {
if (object instanceof Property) {
property = (Property) object;
break;
}
}
} catch (Exception e) {
// $NON-NLS-1$
log.warn(DefaultMessagesImpl.getString("UpdatePathProperty_UpdateFailed", file.getAbsolutePath()), e);
ok = false;
}
if (property != null) {
try {
saveObject(emfUtil, file, uri, property);
} catch (Exception e) {
// $NON-NLS-1$
log.error(DefaultMessagesImpl.getString("UpdatePathProperty_UpdateError", property, file, uri), e);
ok = false;
}
}
}
}
return ok;
}
Aggregations