Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Support for MSBuild item and item metadata expressions in project files.
- `ExhaustiveEnumCase` analysis rule, which flags `case` statements that do not handle all values in an enumeration.
- **API:** `EnumeratorOccurrence` type.
- **API:** `ForInStatementNode::getEnumeratorOccurrence` method.
Expand All @@ -33,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Detect tab-indented multiline strings in `TabulationCharacter`.
- Improve support for evaluating name references in compiler directive expressions.
- Improve overload resolution in cases involving generic type parameter constraints.
- Improve handling for MSBuild properties, items, and conditional evaluation.

### Deprecated

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Sonar Delphi Plugin
* Copyright (C) 2025 Integrated Application Development
*
* 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 au.com.integradev.delphi.enviroment;

import au.com.integradev.delphi.msbuild.MSBuildParser;
import au.com.integradev.delphi.msbuild.MSBuildState;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Map;

public class EnvironmentProjVariableProvider implements EnvironmentVariableProvider {
private final MSBuildState state;

public EnvironmentProjVariableProvider(
Path environmentProj, EnvironmentVariableProvider baseProvider) {
if (environmentProj != null && Files.exists(environmentProj)) {
var parser = new MSBuildParser(environmentProj, baseProvider);
state = parser.parse();
} else {
state =
new MSBuildState(
environmentProj, environmentProj, baseProvider.getenv(), Collections.emptyMap());
}
}

@Override
public Map<String, String> getenv() {
return state.getProperties();
}

@Override
public String getenv(String name) {
return state.getProperty(name);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Sonar Delphi Plugin
* Copyright (C) 2025 Integrated Application Development
*
* 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 au.com.integradev.delphi.msbuild;

import au.com.integradev.delphi.enviroment.EnvironmentVariableProvider;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final class DelphiMSBuildUtils {
private static final Logger LOG = LoggerFactory.getLogger(DelphiMSBuildUtils.class);

private DelphiMSBuildUtils() {
// Utility class
}

public static List<Path> getSourceFiles(MSBuildState state) {
return state.getItems("DCCReference").stream()
.filter(item -> item.getMetadata("Extension").equalsIgnoreCase(".pas"))
.map(MSBuildItem::getPath)
.filter(path -> regularFileExists(path, "DCCReference"))
.collect(Collectors.toList());
}

public static List<DelphiProject> getProjects(
MSBuildState state, EnvironmentVariableProvider environmentVariableProvider) {
return state.getItems("Projects").stream()
.map(MSBuildItem::getPath)
.filter(path -> regularFileExists(path, "Projects"))
.map(
path ->
new DelphiProjectFactory()
.createProject(new MSBuildParser(path, environmentVariableProvider).parse()))
.collect(Collectors.toList());
}

private static boolean regularFileExists(Path path, String specifiedBy) {
if (Files.exists(path) && Files.isRegularFile(path)) {
return true;
} else {
LOG.warn("File specified by {} does not exist: {}", specifiedBy, path);
return false;
}
}
}
Loading