📄 alternativeviewsprovider.java
字号:
/*
* $Id$
*
* Copyright (C) 2000-2005 Polarion Software
* All rights reserved.
* Email: xray@isandia.cz
*
*
* Copyright (C) 2004-2005 Polarion Software
* All Rights Reserved. No use, copying or distribution of this
* work may be made except in accordance with a valid license
* agreement from Polarion Software. This notice must be
* included on all copies, modifications and derivatives of this
* work.
*
* Polarion Software MAKES NO REPRESENTATIONS OR WARRANTIES
* ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESSED OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. DISNET SOFTWARE, a.s.
* SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT
* OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*
*/
package org.polarion.svnwebclient.decorations.impl;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.polarion.svnwebclient.authorization.impl.BindSessionsFilter;
import org.polarion.svnwebclient.decorations.IAlternativeViewProvider;
import com.polarion.core.util.SimpleCache;
import com.polarion.subterra.server.core.cli.service.ServiceException;
import com.polarion.xray.core.projects.ProjectUtils;
import com.polarion.xray.core.reports.ReportsRepository;
/**
*
*
* @author <A HREF="mailto:michal.dobisek@islandia.cz">Michal Dobisek</A>, ISLANDIA s.r.o.
* @version $Revision$ $Date$
*/
public class AlternativeViewsProvider implements IAlternativeViewProvider {
private static Logger log = Logger.getLogger(AlternativeViewsProvider.class);
private static final Map NAME2LOC;
static {
Map work = new HashMap();
work.put("JavaDoc", ".reports/maven/apidocs");
work.put("JCoverage", ".reports/maven/jcoverage");
work.put("XRef", ".reports/maven/xref");
NAME2LOC = Collections.unmodifiableMap(work);
}
SimpleCache pathCache = new SimpleCache("Path cache", 100);
/**
*
*/
public AlternativeViewsProvider() {
super();
}
/* (non-Javadoc)
* @see org.polarion.svnwebclient.decorations.IAlternativeViewProvider#getAlternativeViewContentUrl(java.lang.String, long, long, java.lang.String)
*/
public String getAlternativeViewContentUrl(String resourcePath, long revision, long line, String viewName) {
try {
// Returns /polarion/reports/PROJECT_PATH/REPORT_PATH/JAVA_PATH
// get PROJECT_PATH
IPath projectPath = null;
try {
String projectId = ProjectUtils.getContainerProjectId(new Path(resourcePath));
projectPath = ProjectUtils.getProjectPath(projectId);
} catch (ServiceException e) {
log.warn("Unable to get enclosing project for path "+resourcePath, e);
}
// get REPORT_PATH
String reportPath = (String) NAME2LOC.get(viewName);
// get JAVA_PATH
IPath javaPath = (IPath) pathCache.get(resourcePath);
String sessionId = "?sessionId="+BindSessionsFilter.getSessionId();
// Add them together
return new Path("/polarion/reports/").append(projectPath).append(reportPath).append(javaPath).toString()+sessionId;
} catch(RuntimeException e) {
return null;
}
}
public String[] getAvailableAlternativeViews(String resourcePath, long revision) {
// ignore non .java files
if(!resourcePath.endsWith(".java")) {
return new String[0];
}
IPath path = new Path(resourcePath);
// Get project
String projectId = null;
IPath projectPath = null;
try {
projectId = ProjectUtils.getContainerProjectId(path);
if(projectId != null) {
projectPath = ProjectUtils.getProjectPath(projectId);
}
} catch (ServiceException e) {
log.warn("Unable to get enclosing project for path "+path, e);
}
if(projectId == null || projectPath == null) {
return new String[0];
}
// Get project folder in RR
File rrRoot = ReportsRepository.getInstance().getLocalRoot();
File projectRoot = new File(rrRoot, projectPath.toString());
// Remove the project folder (there must be atl east one
path = path.removeFirstSegments(1);
path = path.removeFileExtension().addFileExtension("html");
List result = new ArrayList();
IPath javaPath = null;
for (Iterator iter = NAME2LOC.keySet().iterator(); iter.hasNext();) {
String repName = (String) iter.next();
IPath jPath = findReport(projectRoot, path, repName, javaPath);
if(jPath != null) {
result.add(repName);
javaPath = jPath;
}
}
// We found the report - cache resourcePath -> javaPath
if(javaPath != null) {
pathCache.put(resourcePath, javaPath);
}
// TODO Now, check for more complicated reports
String[] strResult = new String[result.size()];
result.toArray(strResult);
return strResult;
}
/**
* @param projectRoot
* @param path
* @param string
* @return
*/
private IPath findReport(File projectRoot, IPath path, String reportName, IPath javaPath) {
String reportPath = (String) NAME2LOC.get(reportName);
// getReport root
File reportRoot = new File( projectRoot, reportPath);
if(javaPath == null) {
if(!reportRoot.exists()) {
return null;
}
// Try to fith the path to some report
while(path.segmentCount() > 0) {
File report = new File(reportRoot, path.toString());
if(report.exists()) {
return path;
}
path = path.removeFirstSegments(1);
}
return null;
}
// Else - check existence of report
File report = new File(reportRoot, javaPath.toString());
if(report.exists()) {
return javaPath;
}
return null;
}
}
/*
* $Log$
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -