All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.dotnet.api.microsoft.MicrosoftWindowsEnvironment Maven / Gradle / Ivy

There is a newer version: 2.1
Show newest version
/*
 * Sonar .NET Plugin :: Core
 * Copyright (C) 2010 Jose Chillan, Alexandre Victoor and SonarSource
 * [email protected]
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 */
package org.sonar.plugins.dotnet.api.microsoft;

import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.utils.SonarException;
import org.sonar.plugins.dotnet.api.DotNetConfiguration;

import java.io.File;
import java.util.Map;

/**
 * Class used to share information, between .NET plugins, about Windows and Visual Studio elements, such as:
 * 
    *
  • the environment settings (.NET SDK directory for instance),
  • *
  • the current Visual Studio solution that is being analyzed.
  • *
*/ @InstantiationStrategy(InstantiationStrategy.PER_BATCH) public class MicrosoftWindowsEnvironment implements BatchExtension { private DotNetConfiguration configuration; private boolean locked; // static configuration elements that are fed at the beginning of an analysis and that do not change afterwards private String dotnetVersion; private File dotnetSdkDirectory; private String silverlightVersion; private File silverlightDirectory; private VisualStudioSolution currentSolution; private Map projectsByName; private String workDir; // dynamic elements that will change during analysis private boolean testExecutionDone = false; public MicrosoftWindowsEnvironment() { this(null); } public MicrosoftWindowsEnvironment(DotNetConfiguration configuration) { this.configuration = configuration; projectsByName = Maps.newHashMap(); } /** * After invoking this method, the {@link MicrosoftWindowsEnvironment} class won't be able to index files anymore: if * {@link #indexFile(SourceFile, File)} is called, a {@link IllegalStateException} will be thrown. */ public void lock() { this.locked = true; } private void checkIfLocked() { if (locked) { throw new SonarException("Cannot override attributes that have already been assigned on MicrosoftWindowsEnvironment class."); } } /** * Returns the {@link VisualStudioProject} that is under analysis and which name is the given project name. * * @return the current Visual Studio project */ public VisualStudioProject getCurrentProject(String projectName) { return projectsByName.get(projectName); } /** * Must not be used. * * @param currentSolution * the currentSolution to set */ public void setCurrentSolution(VisualStudioSolution currentSolution) { checkIfLocked(); this.currentSolution = currentSolution; for (VisualStudioProject vsProject : currentSolution.getProjects()) { projectsByName.put(vsProject.getName(), vsProject); } if (configuration != null) { String sonarBranch = configuration.getString("sonar.branch"); if (!StringUtils.isEmpty(sonarBranch)) { // we also reference the projects with the name that Sonar gives when 'sonar.branch' is used for (VisualStudioProject vsProject : currentSolution.getProjects()) { projectsByName.put(vsProject.getName() + " " + sonarBranch, vsProject); } } } } /** * Returns the {@link VisualStudioSolution} that is under analysis * * @return the current Visual Studio solution */ public VisualStudioSolution getCurrentSolution() { return currentSolution; } /** * Must not be used. * * @param dotnetVersion * the dotnetVersion to set */ public void setDotnetVersion(String dotnetVersion) { checkIfLocked(); this.dotnetVersion = dotnetVersion; } /** * Returns the version of the .NET framework to use * * @return the dotnetVersion */ public String getDotnetVersion() { return dotnetVersion; } /** * Must not be used. * * @param dotnetSdkDirectory * the dotnetSdkDirectory to set */ public void setDotnetSdkDirectory(File dotnetSdkDirectory) { checkIfLocked(); this.dotnetSdkDirectory = dotnetSdkDirectory; } /** * Returns the path of the .NET SDK * * @return the dotnetSdkDirectory */ public File getDotnetSdkDirectory() { return dotnetSdkDirectory; } /** * Returns the version of Silverlight that must be used * * @return the silverlightVersion */ public String getSilverlightVersion() { return silverlightVersion; } /** * Must not be used. * * @param silverlightVersion * the silverlightVersion to set */ public void setSilverlightVersion(String silverlightVersion) { checkIfLocked(); this.silverlightVersion = silverlightVersion; } /** * Returns the path tof the Silverlight directory. * * @return the silverlightDirectory */ public File getSilverlightDirectory() { return silverlightDirectory; } /** * Must not be used. * * @param silverlightDirectory * the silverlightDirectory to set */ public void setSilverlightDirectory(File silverlightDirectory) { checkIfLocked(); this.silverlightDirectory = silverlightDirectory; } /** * Tells whether tests have already been executed or not. * * @return true if tests have already been executed. */ public boolean isTestExecutionDone() { return testExecutionDone; } /** * Call this method once the tests have been executed and their reports generated. */ public void setTestExecutionDone() { this.testExecutionDone = true; } /** * Returns the working directory that must be used during the Sonar analysis. For example, it is "target/sonar" if Maven runner is used, * or ".sonar" if the Java runner is used. * * @return the working directory */ public String getWorkingDirectory() { return workDir; } /** * Sets the working directory used during the Sonar analysis. * * @param workDir * the working directory */ public void setWorkingDirectory(String workDir) { this.workDir = workDir; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy